next up previous

Periodic Processes

This contains links to information used in the lectures.


Cron: schedule commands

Periodic commands are handled by the cron daemon. The cron is spawned at boot time. Lines in the cron file are executed by sh. SunOS, HP-UX and ATT systems have a directory to which "cron tables" can be submitted by crontab. cron reads all the files in this directory. This is /var/spool/cron/crontabs on SunOS and HP-UX 10.X and /usr/spool/cron/crontabs under HP-UX 9.X. There is one per user, named with login name of user, run with the users UID.

Old versions of cron periodically scanned the crontabs. Newer ones parse the crontabs and sleep until the time of the soonest. On ATT-like systems (SunOS, HP-UX) crontab tells cron to reread the crontabs. On some systems sending cron a hangup causes rereading.

cron can be made to log, on HP-UX to /usr/lib/cron/log under 9.X, to /var/adm/cron/log under 10.X and to the system log under SunOS.

Crontab File Format

The entries in a crontab file are lines of six fields each. The fields are separated by spaces or tabs. The lines have the following format:
           minute  hour  monthday  month  weekday  command
The first five are integer patterns that specify when the sixth field, command, should be executed. They can have the following ranges of values:
           minute         The minute of the hour, 0-59

           hour           The hour of the day, 0-23

           monthday       The day of the month, 1-31
           month          The month of the year, 1-12

           weekday        The day of the week, 0-6, 0=Sunday

           0   0   1,15   *   1   command
runs command at midnight on the first and fifteenth of each month, as well as every Monday. To specify days in only one field, set the other field to asterisk (*). For example,
           0   0   *   *   1   command
runs command only on Mondays. The sixth field, command (the balance of a line including blanks in a crontab file), is a string that is executed by the shell at the specified times. A percent character (%) in this field (unless escaped by a backslash (\)) is translated to a newline character, dividing the field into "lines". Only the first "line" (up to a % or end-of-line) of the command field is executed by the shell. Any other "lines" are made available to the command as standard input. On HP-UX cron invokes the command from the user's HOME directory with the POSIX shell, (/usr/bin/sh). cron supplies a default environment for every shell, defining:
           HOME=user's-home-directory
           LOGNAME=user's-login-id
           PATH=/usr/bin:/usr/sbin:.
           SHELL=/usr/bin/sh

Security

On ATT like systems (SunOS, HP-UX) the systems administrator can specify who can use cron. This is done using 2 files cron.allow and cron.deny. These are in /usr/lib/cron/ under HP-UX 9.X, /var/adm/cron/ under HP-UX 10.X and SunOS. Users are permitted to use crontab if their names appear in the file cron.allow. If that file does not exist, the file cron.deny is checked to determine if the user should be denied access to crontab. If neither file exists, only root is allowed to submit a job. If only cron.deny exists and is empty, global usage is permitted. The allow/deny files consist of one user name per line.

Standard Uses



next up previous


Paul A. Farrell
Tue Feb 27 02:13:57 EST 1996 Tue Feb 27 02:41:41 EST 1996