Toolserver:Cron

cron is a Unix program that allows users to schedule scripts to run at set intervals.

A crontab is the file that cron uses to determine what actions to perform and when. A cronjob is a the specific line (or job) in the crontab.

Basic commands
crontab has three basic commands: $ crontab -e $ crontab -l $ crontab -r

-l shows a current copy of your crontab tab.

-e allows the user to edit their crontab. It will create a crontab if one does not previously exist. (You can specify which editor to use in your .bash_profile file.) Save your crontab after editing it. The default command to do so is Ctrl-K X.

-r removes your crontab.

Syntax
minute (0-59), 3      2       *       *       0,6     /some/command/to/run 3      2       *       *       1-5     /another/command/to/run >/dev/null
 * hour (0-23),
 * |      day of the month (1-31),
 * |      |       month of the year (1-12),
 * |      |       |       day of the week (0-6 with 0=Sunday).
 * |      |       |       |       commands

Be sure to end your file with a newline (\n). If you don't, you won't receive an error message, but nothing will happen at the scheduled time.

An example which would run on the Toolserver every hour would be: * */1 * * * php /home/myusername/scripts/myscript.php

Any lines beginning with a # will be treated as code comments.

Output
Cron will email you every time a command runs. To avoid this, you can redirect output.

Adding  on the second command redirects normal output to nowhere. This will still email you error messages; you can avoid that by appending, which sends 2 (error messages) to the same place as 1 (normal messages). If you want those to go elsewhere, then specify that instead of, for example:

* */1 * * * php /home/myusername/scripts/myscript.php >/dev/null
 * 1) Redirect normal output to nowhere

Alternately you can specify a MAILTO like: MAILTO=foo@example.com

Shortcuts
string         meaning --         --- @yearly         Run once a year, "0 0 1 1 *". @annually      (same as @yearly) @monthly       Run once a month, "0 0 1 * *". @weekly        Run once a week, "0 0 * * 0". @daily         Run once a day, "0 0 * * *". @midnight      (same as @daily) @hourly        Run once an hour, "0 * * * *".

As well, you can do "every five minutes" using

Troubleshooting
If you receive the error /path/script.php: line 1: ?php: No such file or directory, then try putting an appropriate shebang at the very start of your script, before any  etc: e.g. <?php // Script code
 * 1) !/usr/bin/php

Relative paths will not work; specify the absolute path to any scripts being included.