cancel
Showing results for 
Search instead for 
Did you mean: 

[PAYH] Guides to using CRON as shell access & to unpack tar.gz in Plesk

xpcomputers
Grafter
Posts: 461
Thanks: 1
Registered: ‎13-04-2007

[PAYH] Guides to using CRON as shell access & to unpack tar.gz in Plesk

ADDENDUM:
This has been solved.
The guide to unpacking a tar.gz from a CRON task is in post 6 below in this thread.
A generic guide to using other shell commands from a CRON task is in post 13 below in this thread.


Question in original post:-
I'm trying to work out a way to unpack a tar.gz install file using Plesk control Panel on the new plushost.co.uk trial webspace (PAYH platform).
There seems to be no easy way to do it using the control panel directly, and clearly we don't now have shell access to the webspace.
I've had this idea that it must be possible to do it using the CRON tool. This clearly exposes a command promt - albeit timed and output invisible. I get around the invisible bit, by exporting the screen output to a logfile.
Reading up on the net reveals that to run tar from a CRON command needs full paths or it won't work.
So I've created a working area folder called PUBLIC with full write permissions for my logfiles then run as a CRON command:
whereis tar > /var/www/vhosts/username.plushost.co.uk/httpdocs/public/logfile 2>&1 

This told me that TAR is located in /bin/tar
Then I tried running various permutations of /bin/tar to see if I can get it to unpack my tar.gz (I always set the time for CRON to run about 2 minutes ahead of now).
The most obvious command I thought would work:
/bin/tar -zxvf /var/www/vhosts/username.plushost.co.uk/httpdocs/my-install-file.tar.gz > /var/www/vhosts/username.plushost.co.uk/httpdocs/public/logs 2>&1

.... gives me a permissions problem as seen in the log file:-
silverstripe-v2.2.2/
/bin/tar: silverstripe-v2.2.2: Cannot mkdir: Permission denied
silverstripe-v2.2.2/.htaccess
/bin/tar: silverstripe-v2.2.2/.htaccess: Cannot open: No such file or directory
silverstripe-v2.2.2/assets/
/bin/tar: silverstripe-v2.2.2/assets: Cannot mkdir: No such file or directory
silverstripe-v2.2.2/assets/Uploads/
/bin/tar: silverstripe-v2.2.2/assets/Uploads: Cannot mkdir: No such file or directory
silverstripe-v2.2.2/assets/Uploads/SilverStripeLogo.png
.................etc etc (552KB of similar error log)
The tar is clearly succeeding in trying to unpack my install file (silverstripe CMS in this case), but it is denied access to make the initial folder, so from that point onwards it fails to unpack the resulting files into the archives self-contained folder structure.
It makes me wonder if the command is trying to unpack into the /bin/ folder (where the TAR command is) or if it is trying to unpack into the default folder that CRON runs in (whatever that is). I want it to unpack into the httpdocs folder. I've tried various combinations with a cd command before etc, or in a script with a CD command first to move the correct directory (httpdocs), but then the tar part seems to fail, so my syntax is probably incorrect somewhere.
Can anyone else shed any light on this?
Anyone any idea how I can find out which folder the silverstripe install folder is being denied access to create itself in and how to change this?
If we can crack this generically (to add to the FAQ), then it will immensely help installations of apps onto the platform in the future.
I feel like I am really close.... but so far, no cigar!
58 REPLIES 58
jelv
Seasoned Hero
Posts: 26,785
Thanks: 971
Fixes: 10
Registered: ‎10-04-2007

Re: Unpacking a Tar.gz on new Plushost.co.uk webspace (PAYH platform)

Add [tt]-C /var/www/vhosts/username.plushost.co.uk/httpdocs/[/tt] ?
jelv (a.k.a Spoon Whittler)
   Why I have left Plusnet (warning: long post!)   
Broadband: Andrews & Arnold Home::1 (FTTC 80/20)
Line rental: Pulse 8 Home Line Rental (£14.40/month)
Mobile: iD mobile (£4/month)
xpcomputers
Grafter
Posts: 461
Thanks: 1
Registered: ‎13-04-2007

Re: Unpacking a Tar.gz on new Plushost.co.uk webspace (PAYH platform)

Where would that go? Would that be between the tar.gz bit and the redirect screen to logfile?
eg:
/bin/tar -zxvf /var/www/vhosts/username.plushost.co.uk/httpdocs/my-install-file.tar.gz -C /var/www/vhosts/username.plushost.co.uk/httpdocs/ > /var/www/vhosts/username.plushost.co.uk/httpdocs/public/logs 2>&1

or before the full path of the tar.gz
eg
/bin/tar -zxvf -C /var/www/vhosts/username.plushost.co.uk/httpdocs/ /var/www/vhosts/username.plushost.co.uk/httpdocs/my-install-file.tar.gz > /var/www/vhosts/username.plushost.co.uk/httpdocs/public/logs 2>&1

or does that "C" get merged into the -zxvf part to be -zxvfC.
Thanks for your help.
Mike
jelv
Seasoned Hero
Posts: 26,785
Thanks: 971
Fixes: 10
Registered: ‎10-04-2007

Re: Unpacking a Tar.gz on new Plushost.co.uk webspace (PAYH platform)

I'm guessing a bit here, but I'd try before the -zxvf (you can't put anything between the f and the path to the tar file as f means the next parameter is the file name). It might also work where you had it in your first eg
jelv (a.k.a Spoon Whittler)
   Why I have left Plusnet (warning: long post!)   
Broadband: Andrews & Arnold Home::1 (FTTC 80/20)
Line rental: Pulse 8 Home Line Rental (£14.40/month)
Mobile: iD mobile (£4/month)
xpcomputers
Grafter
Posts: 461
Thanks: 1
Registered: ‎13-04-2007

Re: Unpacking a Tar.gz on new Plushost.co.uk webspace (PAYH platform)

Success!
Thanks Jelv. As I thought, so close yet so far....
I used the line you suggested and added after the tar.gz, which is what http://www.computerhope.com/unix/utar.htm seemed to be suggesting (although they only gave examples for packing up not unpacking).
I now have the unpacked tar.gz in it's self created folder in my httpdocs and the logfile confirms in verbose, that each of the 2500 files and folders were correctly unpacked!
I'll create a guide to this in a minute, so that those following can do this for themselves.
I'd got Kev to unpack the files for me yesterday, which lead to other permissions problems. I couldn't then change the files permissions, move them or even delete them. so had to get Kev to delete them for me. I can confirm that this CRON TAR  method has worked correctly in every way (in that I know "own" the unpacked files, and can change permissions on them myself).
So a complete result ! ! !
I'll post the guide here when done.
Mike
jelv
Seasoned Hero
Posts: 26,785
Thanks: 971
Fixes: 10
Registered: ‎10-04-2007

Re: Unpacking a Tar.gz on new Plushost.co.uk webspace (PAYH platform) SUCCESS!

I think a lot of people are going to be very grateful!
jelv (a.k.a Spoon Whittler)
   Why I have left Plusnet (warning: long post!)   
Broadband: Andrews & Arnold Home::1 (FTTC 80/20)
Line rental: Pulse 8 Home Line Rental (£14.40/month)
Mobile: iD mobile (£4/month)
xpcomputers
Grafter
Posts: 461
Thanks: 1
Registered: ‎13-04-2007

Re: Unpacking a Tar.gz on new Plushost.co.uk webspace (PAYH platform) SUCCESS!

Using CRON to unpack a tar.gz file.
It is very easy when you know how, and here is a detailed, click by click, guide.
I recommend placing the tar.gz install file directly in the HTTPDOCS directory using an ftp client (outside scope of this document).
Note: Before you upload the file, you might want to clear httpdocs directory of all test files & directories not belonging to you that are there by default

  • Logn to Plesk Control Panel

  • In Plesk, at the bottom, click on USERNAME.PLUSHOST.CO.UK (or your listed domain if it is different from this).

  • Click on CRONTAB icon

  • Under SYSTEM USER, choose your main user.

  • Click on SCHEDULE A TASK FOR . . . .

  • I recommend you fill this form in from the bottom upwards. So firstly, in COMMAND box enter as one long line:

/bin/tar -zxvf httpdocs/your-install-file.tar.gz -C httpdocs/ > httpdocs/tar-gz-log 2>&1

    You can copy and paste it, but don't forget to amend the name of your tar.gz file
    If you need to amend anything else, here is what each bit means:-
    /bin/tar -zxvf  =  unpacking command (leave as is, unless you know you need a different command option)
    httpdocs/your-install-file.tar.gz  =  file location & name of your install file go here. Note this is relative to your home directory and has no leading "/" (your home = username.plushost.co.uk)
    -C httpdocs/  =  -C to set creation location, followed by the location you want the file unpacking into (many install files will auto create their own sub-directory here anyway).
    > httpdocs/tar-gz-log 2>&1  =  > redirects all screen comments (2>&1 errors & successes) to a logfile called "tar-gz-log" in the httpdocs directory

  • Click SELECT THE DAY OF WEEK radio button, then choose today's day from the drop down list

  • Click SELECT MONTH OF YEAR radio button, then choose month it is from drop down list.

  • Enter today's date number in day of the month in box

  • In the HOUR box, enter the hour you want the script to run (maybe in about 3 minutes time)

  • In the MINUTE box, enter the minute you want script to run (maybe in about 3 minutes time)

  • Click OK

  • Wait until after your chosen time and then wait a few more minutes to give it time to run (good time to go for a cuppa!)

  • At very top of the page click on USERNAME.PLUSHOST.CO.UK (or your domain if different)

  • Click FILE MANAGER icon

  • Click HTTPDOCS

  • You should now see your unpacked files (or their parent directory at least) and also your tar-gz-log logfile

  • Click the preview icon to the right of tar-gz-log (if the logfile isn't here, something has gone very wrong)

  • Check the logfile contents for any errors (it should tell you it has succeeded in unpacking all the files)

  • Once you are sure it worked, return to CRONTAB to delete the task, so it doesn't run again in a few years time!
    (tick box to left of the task, the click REMOVE SELECTED)

  • You can now carry on following the instructions that came with your install file


Enjoy
(If you find any mistakes or ambiguities, then please post back here so I can correct this guide)
jelv
Seasoned Hero
Posts: 26,785
Thanks: 971
Fixes: 10
Registered: ‎10-04-2007

Re: Guide to using CRON to unpack a tar.gz in Plesk (PAYH/Plushost.co.uk platform)

Mods: Could I suggest that the the post above is extracted to a topic of it's own and made sticky.
jelv (a.k.a Spoon Whittler)
   Why I have left Plusnet (warning: long post!)   
Broadband: Andrews & Arnold Home::1 (FTTC 80/20)
Line rental: Pulse 8 Home Line Rental (£14.40/month)
Mobile: iD mobile (£4/month)
Word_Warrior
Grafter
Posts: 503
Registered: ‎30-07-2007

Re: Guide to using CRON to unpack a tar.gz in Plesk (PAYH/Plushost.co.uk platform)

This is great news, Will be trying it out when I move one of my other domains. Boy, 3500 Joomla files done in a trice! Cheesy
MauriceC
Resting Legend
Posts: 4,085
Thanks: 929
Fixes: 17
Registered: ‎10-04-2007

Re: Guide to using CRON to unpack a tar.gz in Plesk (PAYH/Plushost.co.uk platform)

PUG and the Community Mods have been doing some Pilot testing on the 'Community Support' pages which have mentioned several times in other threads.  This topic seems an ideal candidate to be available at the Launch?  If the originator XPcomputers has no objection, I'll do a 'lift and shift' today.  I'll make sure the attribution to the originator is clear Smiley
And to preempt the question:  No!  I have no firm date for the facility being available, but it should be 'Real soon now!' Lips_are_sealed
Maurice

Superusers are not staff, but they do have a direct line of communication into the business in order to raise issues, concerns and feedback from the community.

zubel
Community Veteran
Posts: 3,793
Thanks: 4
Registered: ‎08-06-2007

Re: Guide to using CRON to unpack a tar.gz in Plesk (PAYH/Plushost.co.uk platform)

Isn't that "Real Soon Nowtm" Smiley
B.
MauriceC
Resting Legend
Posts: 4,085
Thanks: 929
Fixes: 17
Registered: ‎10-04-2007

Re: Guide to using CRON to unpack a tar.gz in Plesk (PAYH/Plushost.co.uk platform)

Pedant  Cheesy 
My excuse - I couldn't remember the ascii code for the symbol. Embarrassed

Superusers are not staff, but they do have a direct line of communication into the business in order to raise issues, concerns and feedback from the community.

xpcomputers
Grafter
Posts: 461
Thanks: 1
Registered: ‎13-04-2007

Re: Guide to using CRON to unpack a tar.gz in Plesk (PAYH/Plushost.co.uk platform)

I have no objections at all. My intention was to make it easier for those following behind! Put it where you like.
Mike
xpcomputers
Grafter
Posts: 461
Thanks: 1
Registered: ‎13-04-2007

Re: Guide to using CRON to unpack a tar.gz in Plesk (PAYH/Plushost.co.uk platform)

A few more CRON tips that I've discovered in the making of the "tar.gz CRON" guide.

Use any shell Command in CRON:
Most shell commands can be run, but need to have the full path to make them work.
eg. tar becomes /bin/tar in CRON
But how do you find out that full path of your command?
If you run a CRON command of:
whereis tar > httpdocs/tar-loc-log 2>&1

This will output the location of the tar command into a logfile called "tar-loc-log" in your httpdocs directory.
The first bit of that logfile says:
/bin/tar
so we know that is the path to use the command in CRON.
Another example to find the path of the useful shell command "env":
whereis env > httpdocs/env-loc-file 2>&1

.....which gives the path of "env" (environment discovery command). The first path listed is /usr/bin/env
So lets use that "env" command and it's path we just discovered:
/usr/bin/env > httpdocs/cron-env-log 2>&1

This will put in the cron-env-log file various facts about our CRON environment. A crucial bit here is PWD - (which means Print Working Directory), which prints the working directory that CRON operates its commands from. Mine is the root of username.plushost.co.uk, but those with their own domain might see something different so run the command to see your PWD.
This tells us that all commands we use must use either a relative path to that PWD or we must use an absolute path.
To use a relative path, you leave off the leading "/" like we have in the location of the logfiles we are creating in the httpdocs directory (which is underneath the root of the working directory):
eg. httpdocs/cron-env-log  references the path username.plushost.co.uk/httpdocs/cron-env-log
To use an absolute path you include the leading "/"
eg. /usr/bin/env  references the path to the env command which is completely outside the username.plushost.co.uk directory

Logfile notes:
You can run any of these tasks without the logfile creation, but you will be running blind, so there is no point in my opinion.
I recommend using a different log file for each job. Just create a unique log file name for each CRON task (with something meaningful) to identify the right log in the httpdocs directory.
If you have an error in your log, I recommend either deleting the log file before running the amended task again, or giving the logfile an incremented name eg. tar-gz-log becomes tar-gz-log2.
This way you will know if the output as the same, or if your task just hasn't run the second time! This could save you headaches in thinking you have tried a combination that would have worked.
(If you really do want to run with a logfile, just delete everything from the first ">" onwards.)
If you want the job to run multiple times and append on to the end of the existing logfile each time, then replace the first ">" with a double one ">>". This should add the info to the bottom of the existing file.

Timing the CRON task:
Set the time to be a suitable interval in the future. How close you can get will depend how accurate your computers own clock is to help you predict the time on the server. To start with allow at least 5 minutes or more maybe (or start lower and work up until it works). Allow a suitable time for the task to have run before checking the results!
I recommend filling in all the entries, including day of the week, as a mishap precaution. Although you could save a few seconds by using an * to mean any day, any month, etc etc, if you forget to delete the CRON task, you might find your CMS or whatever gets overwritten, tomorrow, next week, next month, or even next year. By having the day of week and all other info in the task, it will be currently 6 years until that day of the week is the same date again... and by then you will probably be using a completely different CMS package and even a completely different webserver!

Don't forget to delete the task afterwards:
By using a fully specific set of date & time information, you have made it so your task will only run every 5-6 years (depending on leap years) as a safety measure. However, you really don't want to forget to delete your task once it has run, as you might get a shock in the future! This is even more true if you get lazy and use * instead of specific dates. You have been warned!


Go and use your knowledge:
Now armed with those generic instructions, you should be able to use almost any shell command you need from a CRON task (within reason), or even any script:
Reminder:-

  • Do a whereis to find the full path of your command.

  • Always use the full path of the command

  • The command will execute from within the Working Directory, so use relative & absolute paths accordingly

  • Use a logfile to "see" the result & any error messages

  • You don't have write permissions for the working directory (hence the use of httpdocs/ for the log files and for the output of for example tar unpacking)

  • Use specific date & day in scheduling task (for safety)

  • Check the logfile for the info output (& any errors)

  • Delete the task when you know it has worked!


Now go and have fun!

tex
Grafter
Posts: 69
Registered: ‎30-07-2007

Re: [PAYH] Guides to using CRON as shell access & to unpack tar.gz in Plesk

I don't know why there's so much fuss over cron you can use shell_exec in PHP to do all this. Just make sure the parent directory or target file is CHMOD'ed to something like 0777 otherwise you'll get permission errors. Example:
<?php
// upload an empty file called "stuff.zip", chmod this to 777
echo shell_exec('wget http://example.com/stuff.zip -O stuff.zip 2>&1');
// create folder where contents will be extracted and chmod this too
echo shell_exec('unzip stuff.zip 2>&1');
?>