DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Controlling processes

Executing processes at regular intervals

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   Command
Fields 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
A field can be a number, a range of numbers (for example 10-20), a list of numbers separated by commas, or an asterisk (all values). For example, an asterisk in the ``Hours'' field means ``every hour''; an asterisk in the ``Month'' field means ``every month''.

Let us assume that you want to write a cronfile to issue reminders and perform regular tasks:


Create a file that looks like the following:
   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/tty06
When you have created your file (called cronfile), submit it by typing the following:
   $ crontab cronfile
If 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.


Next topic: Delaying the execution of a process
Previous topic: Running processes at some time in the future

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003