|
|
The crontab(C) command lets you execute routine jobs (called ``cron'' jobs) on a regular basis. For example, it could be used to periodically back up your files, or to periodically clean up tmp and log files. To submit a cron job, details of the job must be added to a cronfile. This is a normal file, but its contents are formatted in a special way:
Minutes Hours Day_of_Month Month Day_of_week CommandFields are separated by spaces or tabs. The file cannot have blank lines. The cronfile parameters are as follows:
Field | Allowable values |
---|---|
Minutes | 0-59 |
Hours | 0-23 |
Day of month | 1-31 |
Month of year | 1-12 |
Day of week | 0-6 (0=Sunday) |
Command | any non-interactive command |
Let us assume that you want to write a cronfile to issue reminders and perform regular tasks:
45 9 * * 1 echo "Weekly status meeting" > /dev/tty06 30 16 1 * * find $HOME -name '#*' -atime +3 -exec rm -f {} \; 0 9 * * 1-5 echo date > /dev/tty06When you have created your file (called cronfile), submit it by typing the following:
$ crontab cronfileIf you want to edit an existing cron job, the cronfile should be edited and re-submitted.
To display the current cron job, type crontab -l. Redirect the output to a file and edit it, then re-submit the new file. This replaces the old cron job.
To remove the current cron job, type crontab -r. If you submit a second cronfile before the first one is executed, the first one will be overwritten by the second.
As with at and batch, access to crontab can be turned on and off by the root user by adding user names to /usr/lib/cron/cron.allow and /usr/lib/cron/cron.deny respectively.