Monday, May 23, 2011

cron on linux quick reference

how to start a cron service?
sudo /usr/bin/service cron start

how to stop a cron service?
sudo /usr/bin/service cron stop

how to restart a cron service?
sudo /usr/bin/service cron restart

how to reload cron settings
sudo /usr/bin/service cron reload

how to list cron service
cron -l

how to edit cron service
cron -e

how to check the last time a crontab get modified?
go to /var/spool/cron, check the user's file's modfied datetime

cron format:
m h dom mon dow   command
* * * * * cmd

first * is minute0-59, second * is hour(0-23), third * is day of month(1-31), forth * is month(1-12), the last * is day of week(0-6,0 is Sunday)

*/5 * * * * cmd: / means every, so the first */5 mean every 5 minutes, and this cron means every 5 minutes, run the cmd command

If a crontab cannot run as you expect, please ensure the command PATH is correct before you spend your time checking other issues

No comments: