Toolserver:Cron

cron is a Unix daemon that allows users to schedule programs 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.

For a description of how to use cron, read the crontab(1) manual page. A simplified description of cron is given below.

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 environment.)

-r removes your crontab.

Syntax
minute (0-59), |      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 30     2       *       *       0,6     /some/command/to/run 30     2       *       *       1-5     /another/command/to/run >/dev/null

Use "*" to mean "every"; for example, "30 2 * * *" runs the program at 02:30 UTC), every day of every month. Only specify "day of month" or "day of week", not both.

On Linux, you can write "*/x" to mean "every x". For example, writing "*/10" in the "minute" column means "every ten minutes". This doesn't work on Solaris; instead, you can write "10,20,30,40,50".

If you use the joe editor, be sure to end your file with a blank line. If you don't, you won't receive an error message, but nothing will happen at the scheduled time. Other editors, including nano (the default editor) don't have this problem.

An example which would run every hour on the hour would be: 0 * * * * php $HOME/scripts/myscript.php

Any lines beginning with a # will be treated as comments, and ignored.

Output
Cron will email you every time a command produces output. To avoid this, you can redirect the output to a file, or discard it.

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

0 * * * * php $HOME/scripts/myscript.php >/dev/null
 * 1) Redirect normal output to nowhere

You can also change the address to which cron will send output by writing a MAILTO line in your crontab: MAILTO=foo@example.com

Shortcuts
Note: these are non-portable and only work on Linux.

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 * * * *".