Some operations must be executed from time to time, for instance, checking if mail has arrived or making a back up. Usually these tasks are done by the system itself, but an user may also want to register some of his/her scripts to be automatically executed at some times.
Calling the scripts is done by the process cron, which is started at boot time -- you do not need to run the program yourself. If you want to schedule a task, all you have to do is to register it in the system, using an auxiliary tool called crontab.
This tool updates the cron table (hence the name) of tasks. To register a task you need to say what should be executed and how often it should run. This is done by writing a line with six fields, in this order: minute, hour, day of month, month, day of week and the command. The fields are separated by spaces or tabs.
As you can see, the first five fields specify the time and seem to very
restrictive, but in fact each of them can be very flexible. An *
means any value and ranges or lists are allowed. This is best explanied
by some examples (you may want to try them):
* * * * * date >> ~/Timespamps
*/5 * * * * date >> ~/Timespamps
30 7-10,17-20 * * 1-5 date >> ~/Timespamps
curie@somewhere.fr
every November, 0 8 7 11 * echo "Happy birthday, Marya!" | mail -s "For you" curie@somewhere.fr
% is transformed into newline, and anything
after the first % is passed to the standard input of the
command. The last example above could be written as:
0 8 7 11 * mail "For you" curie@somewhere.fr % Happy Birthay, Marya! %% myself %
You need to write the list of tasks in a file and call crontab to register them. You can check the current list you have by issuing
crontab -l
If you prefer, you can edit the system copy of your list directly with
crontab -e. To remove all your tasks from the system, use
crontab -r.