Cloud Hosting/Cron
From XMission Wiki
Cron enables users to schedule jobs (commands or shell scripts) to run automatically at a certain time or date. It is commonly used to automate system maintenance or administration. Some CMS like Drupal use cron to automate some tasks.
To edit what jobs are scheduled, first SSH to your container, then run:
crontab -e
This should open up an empty crontab if this is your first time using Cron.
Cron uses the following syntax to schedule jobs.
5 * * * * /user/bin/php5 /path/to/script >/dev/null 2>&1 minute hour day month day-of-week command-line-to-execute
Some examples of proper scheduling syntax:
*/5 * * * * : Run cron every 5 minutes * */1 * * * : Run cron every hour * * */3 * * : Run cron every 3 days * * * */1 * : Run cron once every month */5 * */3 * * : Run cron every 5 minutes, all day, every 3rd day. 30 0 * * * : Run cron at 12:30 every day
An example of a cron job which will remove all the contents of a cache directory every 3 days:
* * */3 * * rm -rf /var/www/vhosts/domain.com/http_docs/cache/*
If you want to see the output, you can have it email to you:
*/5 * * * * /usr/bin/php5 /path/to/script 2>&1 | Mail -E -s "Email Subject here" address@domain.com
You can also redirect the output to a log file:
*/5 * * * * /usr/bin/php5 /path/to/script >> /home/users/u/username/cronlog.log 2>&1
- Adding >> will continue to append the log. If you just want to see the output once just add > instead of >>
To list all cronjobs in your crontab:
crontab -l