The 'cron' package is installed by default on every Linux system and is part of the base package (The "base" software packages required to run a basic Linux installation). It is very useful to handle routine tasks and processes (maintenance/"clean up" tasks for example), and can execute commands scheduled for any time, specified by its configuration.
Cron runs as a daemon in the background, and is started automatically on every boot-up, though it can also be started manually. It's configuration file (crontab) can be found in /etc and is easy to understand. Cron looks up the configuration file's table every minute to check if there is any tasks that need executed. It should look similar to the following:
# Minute Hour Day Month Weekday Command
5 22 * * * test -x /usr/sbin/texpire && /usr/sbin/texpire
59 23 * * * /usr/bin/xmessage.sh
0 0 * * 1 /usr/bin/xmessagedel.sh
1 0 * * 1 /usr/bin/xsoftwaresamba.sh
You can use the following as a reference:
Minutes | 0-59 and * for all Minutes
Hours | 0-23 and * for all Hours
Days | 1-31 and * for every Day
Months | 1-12 and * for every Month
Week days | 0-7 and * for every Weekday (0 and 7 for Sunday)
The scheduled tasks can also be seen by issuing the command 'crontab -l', which displays the table in the crontab file.
Well, in the above example... the first two tasks are run daily: the first time at 22:05 and the second at 23:59. The last two tasks are run once per week, at 0:00 and 0:01.
Some more examples:
The script 'xmanager.sh' will be run daily at 0:00 and 12:00:
0 0,12 * * * /usr/bin/xmanager.sh
On the fifteenth of every month, 'xmail.sh' will be run at 12:30:
30 12 15 * * /usr/bin/xmail.sh
abc.sh will be run every friday at 0:00 o'clock:
0 0 * * 5 /usr/bin/abc.sh
Everyday xmail.sh is run from 6-23 o'clock at a 15min interval:
*/15 6-23 * * * root /usr/bin/xmail.sh
For further assistance, issue the command 'man crontab' and read the informative man page of cron.
Written by: MaDvLaD (9 March 2005)
MaDvLaD is Member Of Community Projects, Planning & Development
This article was originally published by CyberArmy.net in the CyberArmy Library.
|