return to first page linux journal archive
keywordscontents
Cron is a program for running other programs at regular intervals. It uses a file (called a crontab) to control which programs to run and when. To list your crontab file, use crontab -l.

The format of the crontab is reasonably simple. Each line (excluding blanks and those beginning with [cw]#[ecw]) has six fields: minute, hour, day, month, dayofweek, and command. For example (from the crontab man page):

# at 6:10 a.m. every day
10 6 * * * date

This allows us to set up regular backups. Like this:

# Every morning at 3 a.m., run my backup script
0 3 * * * /usr/local/bin/my_backup_script

or this:

# I only want backups on weekdays---I don't
# come in at weekends to change the tape!
0 3 1-5 * * /usr/local/bin/my_backup_script

Suppose my_backup_script checks for the existence of a file called /etc/last_backup. If it exists, only back up files newer than it, if not, back up everything. We could ensure that we do a full backup every week by:

# Every Monday at 1 a.m. delete /etc/last_backup
0 1 1 * * rm /etc/last_backup

Using crontab to automatically make backups in this way saves you time, as well as allowing you to schedule the backup for a time when your system isn't being used too much. Just don't forget to change the tape each day! [Alternately, you can append each new backup to the end of the tape. See Tar and Taper for Linux, and Backing up in Linux in this issue for more details.--ED]


Back to article