24.1 Introduction to cron

   

Jobs may be scheduled to run at a specified time using cron . It serves two types of jobs, submitted either by the crontab or the at command. The crontab command creates a file that is read and executed according to the schedule contained within the file. Programs listed in these files are executed on a regular basis. On the other hand, the at command creates files that are removed after the execution of the program. Thus, any program scheduled using the at command is executed only once. The cron daemon is started at boot time at run level 2. It reads crontab and at files created in the /var/spool/cron directory at startup and schedules the programs for a given time.

The cron Daemon

The cron daemon is started at run level 2 and stopped at run level 1. A variable named CRON in the /etc/rc.config.d/cron file controls whether the daemon will be started at boot time. If this variable value is 1, the daemon is started at boot time, and if the value is zero (0), the daemon is not started. The startup script for the cron daemon is /sbin/init.d/cron and is nor mally executed at boot time. To start the daemon manually, you can use the following command.

 /sbin/init.d/cron start 

To stop the cron daemon at any time, use the following command.

 /sbin/init.d/cron stop 

Start and stop link files for this script are /sbin/rc2.d/S730cron and /sbin/rc1.d/K270cron . At startup, the daemon reads its configuration files and schedules its tasks . Other than crontab files, the cron daemon also schedules programs timed with the at command.

If you make a change to any of the configuration files manually, you may stop and restart the cron script so that it reads its configuration files again. However, if you use the crontab command to modify a configuration file, the command automatically updates cron schedules and you don't need to restart the daemon.

Granting Access to Users

Two files are used to allow/deny access to the cron daemon for ordinary system users. These files are /var/adm/cron/cron.allow and /var/adm/cron/cron.deny . If neither of these files is present, only the root user can access cron . If both of these files are present, the precedence goes to the cron.allow file, and all users who are listed in this file are allowed to use cron . If cron.allow exists but is empty, only the root user can use cron . If only the cron.deny file exists, all users except those listed in this file are allowed to use cron . Table 24-1 shows the use of these two files in allowing or denying cron access.

Table 24-1. Role of cron Files to Allow/Deny Use of cron .
cron.allow cron.deny Effect on User
Not exists Not exists Only the root user can use cron .
Not exists Exists All users except those listed in cron.deny can use cron .
Not exists Exists (empty) All users can use cron .
Exists Not exists Only those users listed in the cron.allow file can use cron .
Exists Exists Only those users listed in the cron.allow file can use cron .
Exists (empty) Not exists Only the root user can use cron .
Exists (empty) Exists Only the root user can use cron .

Warning

You must be careful of the case where cron.allow does not exist and cron.deny exists but is empty. In this case, all users of the system are granted cron access.


When a user tries to create a schedule, these two files are checked for access rights. Only those users who are granted cron access are allowed to create schedules.

Log Files

The cron daemon creates its log files in the /var/adm/cron directory. The /var/adm/cron/log file is used to log all cron activity. Contents of the file look like the following.

 !*** cron started *** pid = 1961 Sun Nov 11 14:41:11 EST 1999 >  CMD:  /home/root/trimlog >> /home/root/trimlog.log >  root 2316 c Sun Nov 14 14:42:00 EST 1999 <  root 2316 c Sun Nov 14 14:42:02 EST 1999 >  CMD:  /home/root/cleandisk  >> /home/root/cleandisk.log >  root 2459 c Sun Nov 14 14:43:00 EST 1999 <  root 2459 c Sun Nov 14 14:52:00 EST 1999 >  CMD: /usr/sbin/lpsched -v >  root 2672 c Sun Nov 14 14:45:00 EST 1999 <  root 2672 c Sun Nov 14 14:45:06 EST 1999 

As you can see from the file, the first line shows the start time of the cron daemon and its PID. This time is logged whenever cron starts. Lines containing CMD show a command that is executed. Lines that start with the greater-than symbol ( > ) show the start time of the job with an ID number. Lines starting with the less-than symbol ( < ) show the completion time of the job.


   
Top


HP Certified
HP Certified: HP-UX System Administration
ISBN: 0130183741
EAN: 2147483647
Year: 2000
Pages: 390
Authors: Rafeeq Rehman

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net