|
Kansas State University at Salina Introduction to Unix |
|
Linux for Programmers and Users, Section 4.7.
You may want to schedule some programs to run at later time or want them to run on a regular, repeating schedule. Examples of when you might want to do this are:
Unix has a facility for running scheduled tasks called cron, but users do run cron directly. It is always running in the background to run scheduled commands at the appropriate times. We call system programs, such as cron, that run in the backgroud daemons.
Note
The output from any scheduled commands, is by default sent to the user in an e-mail message. If this is not desired, then when scheduling the command, redirect the output from the command to a file or to the system provided trash can (/dev/null).
If you receive an e-mail message from the cron daemon, you might try using mutt, to read the message.
The programs that users use to schedule programs are crontab and at.
SYNOPSIS
crontab [-u user] [file]
crontab [-u user] -l | -r [-i] | -e
DESCRIPTION
Crontab is the program used to install, deinstall or list the tables used to drive the cron daemon for running commands on a repeating schedule.
The first usage is to install a schedule of commands from a file or from standard input. If no options are specified, it reads from standard input.
- -u user¶
Specify which user’s schedule to adjust (only for root). The default is for your own account.
- -l¶
List the currently scheduled commands
- -r¶
Remove the currently scheduled commands
- -i¶
Prompt the user to confirm removal of the scheduled commands
- -e¶
Edit the list of scheduled commands. After saving the temporary file and exiting from the editor, the commands entered in the file are scheduled. The default editor used is vi. If you wish to use another editor, such as nano, set your EDITOR environment variable:
export EDITOR='nano'
crontab file format
SYNOPSIS
at -r job | -l | TIME
DESCRIPTION
The at command is used to schedule a command to run one time.
- -r job¶
Remove scheduled jobs, identified by their job number. This is the same as running atrm job
- -l¶
List the scheduled jobs
- TIME
TIME is a very flexible specification of when the command should run. See the text book for examples. at then reads from standard input for list of commands to run at this time. Type the EOF character (Cntrl-d) when finished entering commands.
Footnotes
| [1] | Give some though to where you might want to use a wildcard (*) character. A wildcard in the day field, means that that the day of the month is not important – other criteria such weekday will determine when the program runs. However, a wildcard in the minute field would mean that for the specified hour, the command runs once for every minute (60 times). |