System Administration Guide, Volume 2

Executing Routine Tasks Automatically

Many routine system events can be set up to execute automatically. Some of these tasks should occur repetitively, at regular intervals. Other tasks need to run only once, perhaps during off hours such as evenings or weekends.

This section contains overview information about two commands, crontab and at, which enable you to schedule routine commands to execute automatically, avoiding peak hours or repeating commands according to a fixed schedule. crontab schedules repetitive commands, while at schedules commands that execute once.

Scheduling Repetitive Jobs: crontab

You can schedule routine system administration commands to execute daily, weekly, or monthly by using the crontab commands.

Daily crontab system administration tasks might include:

Weekly crontab system administration tasks might include:

Monthly crontab system administration tasks might include:

Additionally, users can schedule crontab commands to execute other routine system tasks, such as sending reminders and removing backup files.

For more information about scheduling crontab jobs, see Chapter 30, Scheduling System Events (Tasks).

Scheduling a Single Job: at

The at command allows you to schedule a job for execution at a later time. The job may consist of a single command or a script.

Like crontab, at allows you to schedule the automatic completion of routine commands. However, unlike crontab files, at files execute their commands once, and then are removed from their directory. Therefore, at is most useful for running simple commands or scripts that direct output into separate files for later examination.

Submitting an at job involves entering a command, following the at command syntax to specify options to schedule the time your job will be executed. For more information about submitting at jobs, see "at Command Description".

The at command stores the command or script you entered, along with a copy of your current environment variable in the /var/spool/cron/atjobs directory. As a file name, your at job file is given a long number specifying its location in the at queue, followed by the .a extension, such as 793962000.a.

The cron daemon periodically executes the atrun program, usually at 15-minute intervals. atrun then executes at jobs at their scheduled times. After your at job has been executed, its file is removed from the atjobs directory.

For more information on scheduling at jobs, see Chapter 27, Examining and Changing System Information (Tasks).