SourceForge VA Linux Systems
Copyright © 2000 Paul Sheer - Click here for copying permissions       Source by FTP

next up previous contents index
Next: postgres SQL server Up: Rute Users Tutorial and Previous: httpd Apache   Contents   Index

Subsections

crond and atd

Add comments here 
crond and atd are two very simple and important services that everyone should be familiar with. crond does the job of running commands periodically (daily, weekly), while atd's main feature is run a command once at some future time.
These two services are so basic that we are not going to detail their package contents and invocation.

/etc/crontab configuration file

The /etc/crontab file dictates a list of periodic jobs to be run -- like updating the locate and whatis databases, rotating logs, and possibly performing backup tasks. If there is anything that needs to be done periodically, you can schedule that job in this file. /etc/crontab is read by crond on startup. crond will already be running on all but the most broken of UNIX systems.
After modifying /etc/crontab, you should restart crond with /etc/rc.d/init.d/crond restart.
/etc/crontab consists of single line definitions for what time of the day/week/month a particular command should be run.
Each line has the form:

 
<time> <user> <executable>

<time> is a time pattern that the current time must match for the command to be executed. <user> tells under what user the command is to be executed. <executable> is the command to be run.

The time pattern gives the minute, hour, month-day, month, and week-day that the current time is compared. The comparison is done at the start of every single minute. If crond gets a match, it will execute the command. A simple time pattern is as follows.

 
50 13 2 9 6 root /usr/bin/play /etc/theetone.wav

Which will play the given WAV file on Sat Sep 2 13:50:00 every year, while

 
50 13 2 * * root /usr/bin/play /etc/theetone.wav

will play it at 13:50:00 on the 2nd of every month, and

 
50 13 * * 6 root /usr/bin/play /etc/theetone.wav

will do the same on every Saturday. Further,

 
50 13,14 * * 5,6,7 root /usr/bin/play /etc/theetone.wav

will play at 13:50:00 and at 14:50:00 on both Friday, Saturday and Sunday, while

 
*/10 * * * 6 root /usr/bin/play /etc/theetone.wav

Will play every 10 minutes the whole of Saturday. The / is a special notation meaning ``in steps of''.

In the above examples, the play command is executed as root.
The following is an actual /etc/crontab file:

 
 
 
 
5 
 
 
 
 
10 
 
 
 
 
# Environment variables first
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# Time specs
30 20 * * * root /etc/cron-alarm.sh
35 19 * * * root /etc/cron-alarm.sh
58 18 * * * root /etc/cron-alarm.sh
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

Note that the # character is used for comments as usual. crond also allows you to specify environment variables under which commands are to be run.
Your time additions should come like mine have, to remind me of the last three Metro trains of the day.
The last four entries are vender supplied. The run-parts command is a simple script to run all the commands listed under /etc/cron.hourly, /etc/cron.daily etc. Hence, if you have a script which needs to be run every day, but not at a specific time, you needn't edit your crontab file: rather just place the script with the others in /etc/cron.<interval>.
My own /etc/cron.daily/ directory contains:

 
 
 
 
5 
 
 
 
 
10 
total 14
drwxr-xr-x    2 root     root         1024 Sep  2 13:22 .
drwxr-xr-x   59 root     root         6144 Aug 31 13:11 ..
-rwxr-xr-x    1 root     root          140 Aug 13 16:16 backup
-rwxr-xr-x    1 root     root           51 Jun 16  1999 logrotate
-rwxr-xr-x    1 root     root          390 Sep 14  1999 makewhatis.cron
-rwxr-xr-x    1 root     root          459 Mar 25  1999 radiusd.cron.daily
-rwxr-xr-x    1 root     root           99 Jul 23 23:48 slocate.cron
-rwxr-xr-x    1 root     root          103 Sep 25  1999 tetex.cron
-rwxr-xr-x    1 root     root          104 Aug 30  1999 tmpwatch

It is advisable to go through each of these now to see what your system is doing to itself behind your back.

The at command

at will execute a command at some future time. I suppose it is essential to know, although I never used it myself until writing this chapter. at is the front to the atd daemon which, like crond will almost definitely be running.
Try our wave file example, remembering to press Ctrl-D to get the <EOT> (End Of Text):

 
 
 
 
5 
[root@cericon /etc]# at 14:19
at> /usr/bin/play /etc/theetone.wav
at> <EOT>
warning: commands will be executed using /bin/sh
job 3 at 2000-09-02 14:19

You can the type atq to get a list of current jobs:

 
3       2000-09-02 14:19 a

a means is the queue name, 3 is the job number, and 2000-09-02 14:19 is the scheduled time of execution. While play is executing, atq will give:

 
3       2000-09-02 14:19 =

The at and atd man pages contain additional information.

next up previous contents index
Next: postgres SQL server Up: Rute Users Tutorial and Previous: httpd Apache   Contents   Index
Paul Sheer 2000-10-07