Sunday, February 19, 2012

CRON - cause I always forget

The cron format.
# .---------------- minute (0 - 59)
# |    .------------- hour (0 - 23)
# |    |    .---------- day of month (1 - 31)
# |    |    |    .------- month (1 - 12) OR jan,feb,mar,apr ...
# |    |    |    |    .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat
# |    |    |    |    |
# *    *    *    *    *    [command to be executed]
I addition to the above syntax you can use the following, more easily remembered, special words.
@yearly, @monthly, @daily, @hourly, @reboot (at startup)
These are however not available in every cron daemon.

Every minute
* * * * * /miff/moff/meff.sh
Every five minutes
*/5 * * * * /miff/moff/meff.sh
Every two minutes the first half hour of every hour
0-30/2 * * * * /miff/moff/meff.sh

More examples can be found here.