What is cron? cron is the name of a UNIX program enabling users to run periodic processes at predefined times. The cron daemon (crond) is normally started with system initialisation, crond consults the crontab configuration files every minute. cron has a systemwide configuration file named crontab while individual users may create their own cron configuration file using the crontab command. System examples of cron periodic processes would be to fetch email from a server every x minutes or rotate the system logs once a week. A users use of cron may include a regular backup of the home directory. Why the name cron? cron is simply derived from the greek word cronos meaning time. "vixie cron" being modified and enhanced for linux was developed by Paul Vixie and is referred to in this document simply as cron. System wide services are run from the following directories at specific preset times: /etc/cron.hourly scripts run every hour at one minute past the hour /etc/cron.daily scripts run every day at 04:02am /etc/cron.weekly scripts run weekly on Sunday at 04:22am /etc/cron.monthly scripts run on the first day of each month at 04:42am Below is a listing of the /etc/cron.daily directory on a Red Hat 9 system: total 24 lrwxrwxrwx 1 root root 28 Jan 21 2006 00-logwatch -> ../log.d/scripts/logwatch.pl -rwxr-xr-x 1 root root 276 Jan 25 2003 0anacron -rwxr-xr-x 1 root root 51 Jan 25 2003 logrotate -rwxr-xr-x 1 root root 418 Feb 11 2003 makewhatis.cron -rwxr-xr-x 1 root root 104 Feb 28 2003 rpm -rwxr-xr-x 1 root root 132 Feb 20 2003 slocate.cron -rwxr-xr-x 1 root root 193 Feb 11 2003 tmpwatch Listing descriptions and fuctionality: - The logwatch symbolic link connects to script logwatch.pl a system log analyser and reporter. - 0anacron is a executable script for updating anacrons time stamps. anacron catches any cron jobs that were missed when the system was turned off. - logrotate, also a script, used to rotate system log files. - The makewhatis.cron script creates the database for man -f or whatis command line (keyword) searches. - rpm script creates a database of rpm pakages installed on the system. - slocate.cron is a script for creating a database providing a secure way to index and quickly search for files on your system. - tmpwatch script automatically removes files over a certain age. Files in the /tmp directory are removed if more than ten days old and files in the /var/tmp directory are removed when older than 30 days. The crontab file located in /etc directory, /etc/crontab, is a systemwide configuration file for the cron daemon. An example is given here: SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ # run-parts command is used to run all executable scripts in a directory # min hr dom mon dow user script command 01 * * * * root run-parts /etc/cron.hourly 02 4 * * * root run-parts /etc/cron.daily 22 4 * * 0 root run-parts /etc/cron.weekly 42 4 1 * * root run-parts /etc/cron.monthly 49 22 * * * root /sbin/shutdown -h now # #min=minute, hr=hour, dom=day of month, mon=month, dow=day of week Note how the start time of each script is determined: - An asterisk functions like a wild card when placed in a field. Thus an asterisk in the min column means every miunte, the hr hour column means every hour. - min (range is from 0 - 60) at which this job should be run. To specify multiple values use commas in a list. e.g. 0,10,12,34. To run a job every minute in a range, specify like this 5-10, 24-36. - hr (range 0 - 24) accomodating lists, ranges as for min - dom (range 1 - 31) accomodating lists and ranges as for min - mon (range 1 -12) accomodating lists and ranges as for min - dow (range 0 - 7 where 0 and 7 are both Sunday) lists and ranges are accomodated also - The last entry in the systemwdie crontab file is executed at 22:49pm each day shuting down the computer automatically. crontab (1) maintain crontab files for individual users cron (8) cron daemon to ececute scheduled commands anacron (8) runs commands periodically with a frequency specified in days. does not assume machine is running 24hrs a day and can be used to control daily, weekly and monthly jobs that are usually controlled by cron anacrontab (8) configuration file for anacron