| Setting Automated Tasks with Crontab |
| Thursday, 10 January 2008 | |
|
Cron deamon is a client that wakes up every minute and checks scheduled commands listed in the crontab file (cron table). The crontab file contains information about the time, date and command that needs to be executed at a specific time. For a Linux box, the cron info is usually stored at /var/spool/cron.
Column 1 2 3 4 5 6 | | | | | | * * * * * command Column 1 represents minute (00-59) Column 2 represents hour (00-23) Column 3 specifies day in the month (1-31) Column 4 specifies the month (1-12) Column 5 represents day in a weekday (0-6) with 0 for Sunday, 1 for Monday and so on. Examples An example below shows how to create an automated backup of a directory data to a directory backup, executed every day at 15 minutes pass midnight. 15 0 * * * cp -r /home/data /home/backup The following example runs the command checkquota.pl 15, 30, 45 minutes after the hour every Monday and mails the result to root 15,30,45 * * * 1 /etc/checkquota.pl 2>&1 | /bin/mail -s "Weekly Quota Checked" root Crontab Options The -l option of a crontab is used to display the content of the current user's crontab file, while the -e option is used to modify the current user's crontab file. The environment variable EDITOR can be set to change the default editor, e.g. setenv EDITOR /bin/vim to change the default editor to vim. The -r option of a crontab is used to remove and make the current user's crontab file empty.
|