[Next] [Previous] [Up] [Top] [Contents]

CHAPTER 13 Daily System Administration

13.3 Running programs automatically, cron & at

cron executes periodic commands at specified times and dates. cron is a clock daemon that runs continuously on the system and schedules jobs to be run according to the crontab files. You should use the crontab command to update entries in the crontab database.

at executes a command once at a specified time.

Users are allowed to run the cron and at programs if their names are listed in the file /var/spool/cron/[cron,at].allow (SunOS 4.1.X) or /etc/cron.d/[cron,at].allow (SunOS 5.X). If this file doesn't exist then the file /var/spool/cron/[cron,at].deny (SunOS 4.1.X) or /etc/cron.d/[cron,at].deny (SunOS 5.X) is checked to see if permission should be denied. If neither file exists permission is refused for all but the superuser. If you wish to allow everyone permission create an empty [cron,at].deny file. Ultrix only allows the root user access to crontab.

The crontab files are kept in the directory /var/spool/cron/crontabs for both SunOS 4.1.X and 5.X. Each crontab file is named after the owner. Some typical entries in the root crontab file, /var/spool/cron/crontabs/root, might be:

5 0 * * * calendar -

15 0 * * * /usr/etc/sa -s >/dev/null

# save only last weeks worth of sendmail logs

5 4 * * 6 /usr/lib/newsyslog >/dev/null 2>&1

# backup file systems

10 0 * * 2-6 /usr/local/backup/cron-backup

There are 5 time fields and a command field to control and what program is executed by cron and when,

field values

Time fields can contain single values, comma (,) separated values (match any listed values), hyphen (-) separated values (match any value in the range), or the wildcard (*) (always match).

To edit a crontab file use the command "crontab -e". This will allow you to change the crontab file and will cause cron to re-read it when you're done. By default in Solaris 2.X crontab assumes the ed editor. What you set with your EDITOR environmental variable will override this.

To just list the contents of your crontab file use the command "crontab -l".

Unix System Administration - 8 AUG 1996
[Next] [Previous] [Up] [Top] [Contents]