DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Programming with the UNIX system shell

Executing processes at regular intervals

The crontab(1) command lets you execute routine jobs (called ``cron'' jobs) on a regular basis. For example, it could be used periodically to back up your files, or to 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: Obtaining the status of running processes
Previous topic: Running commands at a later time with the batch and at commands

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004