I’d like to automate, on schedule, a specific task. Suppose every Wednesday at 2am I want to copy a given file from one location to another on my server. How would I go about doing that using a cron job?
Just modify the string as necessary. If you’re copying a folder, use “cp -fr” instead of just “cp”. Or, if you’ll be replacing the same file each day – then you’d need at least cp -f.
From SiteAdmin/CPanel you’d just enter in the appropriate time to execute the command and save. The new cron job will be automatically executed from then on.
Answer #1
Hey Mike,
Cron jobs are laid out as follows:
* * * * * command to be executed
– – – – –
| | | | |
| | | | +—– day of week (0 – 6) (Sunday=0)
| | | +——- month (1 – 12)
| | +——— day of month (1 – 31)
| +———– hour (0 – 23)
+————- min (0 – 59)
You can do this either from SSH in your account or from your SiteAdmin/CPanel under the Cron Jobs section. If from SSH, just do the following:
crontab -e
This will open a command prompt. Then, insert the following line:
0 2 0 0 3 nice -n15 cp /home/USER/public_html/somefile.php /home/USER/public_html/somefolder/
Just modify the string as necessary. If you’re copying a folder, use “cp -fr” instead of just “cp”. Or, if you’ll be replacing the same file each day – then you’d need at least cp -f.
From SiteAdmin/CPanel you’d just enter in the appropriate time to execute the command and save. The new cron job will be automatically executed from then on.
Hope that answered your question!