next up previous contents
Next: 8.2.1 Modifying the system Up: 8. Other Administrative Tasks Previous: 8.1.2 Incremental Backups   Contents

8.2 Scheduling Jobs Using Cron

What is Cron?
 
Cron is a daemon that executes scheduled commands listed in a crontab file. It checks every minute to see if there are ant jobs scheduled to run at that time, if so, it executes those jobs.

The cron deamon is usually started at bootup time.

What is crontab?
 
Crontab is the program used to install, deinstall or list the tables used to drive the cron daemon. Each user can have their own crontab, and though these are files in /var, they are not intended to be edited directly.

What does a crontab file look like?
 
The users crontab file looks like this. (man 5 crontab).

* * * * * command

| | | | |

| | | | - > Day of week, 0 or 7 Sunday, 1 Monday

| | | - - > Month 0-12

| | - - - > Day of month 0-31

| - - - - > Hour of day 0-23

- - - - - > Minute of hour 0-59
The system cron tab looks like the above, with an additional entries.

* * * * * user command
The typical Redhat crontab file looks like this. The times may be different.

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

MAILTO=root

# run-parts

01 * * * * root run-parts /etc/cron.hourly

02 4 * * * root run-parts /etc/cron.daily

22 4 * * 4 root run-parts /etc/cron.weekly

12 4 1 * * root run-parts /etc/cron.monthly
The MAILTO environment variable is used to specify where the output for that particular job should be sent to, if not set, it gets mailed to the owner of the crontab file.

The program run-parts is explained in another section, but what it does is execute every file with the +x (execute) bit set on programs listed in the directory as the option.

So every file in the /etc/cron.hourly will be executed 1 minute after each hour.

Every file in the /etc/cron.daily will be executed at 4:02 AM. You may notice that there is a user logging in at this time called nobody if you happen to monitor your logs. This is one if the programs in the cron.daily directory doing its job.

The cron.weekly is set to run Thursday at 4:22 AM and the cron.monthly is set to run at on the first day of the month at 4:22 AM.



Subsections
next up previous contents
Next: 8.2.1 Modifying the system Up: 8. Other Administrative Tasks Previous: 8.1.2 Incremental Backups   Contents