• No results found

The cron daemon (/usr/sbin/cron for SUSE and /usr/sbin/crond for Red Hat) is responsible for running the cron jobs. Every minute, the cron daemon looks at the crontabs, loads new or modified crontabs into

memory, and checks whether any jobs are scheduled to execute during that minute. The cron daemon is started during the startup scripts at runlevels 2, 3, 4, and 5.

#chkconfig --list crond

crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off

The startup script is /etc/init.d/crond in Red Hat and /etc/init.d/cron in SUSE. For more information on startup scripts, refer to Chapter 1, "System Boot, Startup, and Shutdown Issues."

A log entry is created when cron jobs are run, crontab commands are used, the cron daemon is started, and so on. cron uses the syslog daemon to log cron events. The syslog facility for cron messages is cron. See the syslogd(8) man page for an explanation of how syslog routes messages. The log file for cron is determined by /etc/syslog. conf. Red Hat has a log just for cron, /var/log/cron, to log cron messages. SUSE uses /var/log/messages. A Red Hat /etc/syslog.conf has the following entry to route cron messages to /var/log/cron:

# Log cron stuff

cron.* /var/log/cron

With Red Hat, cron messages are not duplicated in /var/log/messages because of the cron.none on the following syslog.conf line:

*.info;mail.none;news.none;authpriv.none;cron.none /var/log/messages

It would be a simple matter to change SUSE systems to log cron messages to /var/log/cron. Here is a sample of the entries that are written to Red Hat's /var/log/cron file:

Aug 15 04:22:00 sawnee CROND[25198]: (root) CMD (run-parts /etc/cron.weekly)

Aug 15 04:22:04 sawnee anacron[25202]: Updated timestamp for job 'cron.weekly' to 2004-08-15

Aug 15 05:01:00 sawnee CROND[2420]: (root) CMD (run-parts /etc/cron.hourly)

Aug 15 06:01:00 sawnee CROND[2519]: (root) CMD (run-parts /etc/cron.hourly)

Aug 15 07:01:00 sawnee CROND[2532]: (root) CMD (run-parts /etc/cron.hourly)

Aug 15 08:01:00 sawnee CROND[2544]: (root) CMD (run-parts /etc/cron.hourly)

Aug 15 09:01:00 sawnee CROND[2556]: (root) CMD (run-parts /etc/cron.hourly)

Aug 15 10:01:00 sawnee CROND[2568]: (root) CMD (run-parts /etc/cron.hourly)

Aug 15 11:01:00 sawnee CROND[2588]: (root) CMD (run-parts /etc/cron.hourly)

Aug 15 12:01:00 sawnee CROND[2600]: (root) CMD (run-parts /etc/cron.hourly)

Aug 15 13:01:00 sawnee CROND[2612]: (root) CMD (run-parts /etc/cron.hourly)

Aug 15 14:01:00 sawnee CROND[2910]: (root) CMD (run-parts /etc/cron.hourly)

Aug 15 14:35:46 sawnee crontab[3107]: (dave) LIST (dave)

Aug 15 14:36:56 sawnee crontab[3113]: (dave) BEGIN EDIT (dave) Aug 15 14:37:03 sawnee crontab[3113]: (dave) REPLACE (dave) Aug 15 14:37:03 sawnee crontab[3113]: (dave) END EDIT (dave) Aug 15 14:37:09 sawnee crontab[3116]: (dave) BEGIN EDIT (dave) Aug 15 14:37:13 sawnee crontab[3116]: (dave) REPLACE (dave) Aug 15 14:37:13 sawnee crontab[3116]: (dave) END EDIT (dave) Aug 15 14:38:00 sawnee crond[1792]: (dave) RELOAD (cron/dave)

Aug 15 14:38:00 sawnee CROND[3166]: (dave) CMD (/home/dave/daily_rpt)

The sample cron log shows cron activity on host sawnee. cron events are broken out by crond, crontab, and CROND (which shows jobs being started). The number between the [] is the process ID. Everything that crontab performs is logged. Note that run-parts is listed as one job and is not broken down by each job in / etc/cron.hourly.

As we noted earlier, cron and at are similar but not identical across Linux distributions. To understand the differences, look closely at the man pages, see which packages are installed, and look for additional

documentation supplied with the packages. Run rpm -qa to see what packages are installed. This list is from a Red Hat 9.0 system:

# rpm -qa|grep cron crontabs-1.10-5 vixie-cron-3.0.1-74 anacron-2.3-25

# rpm -qa|grep cron cron-3.0.1-824

The package name doesn't indicate it, but this is vixie-cron too, which can be verified in the README supplied with the package.

Look at the files delivered with the packages by running rpm -q --filesbypkg. Take note of man pages, READMEs, and other documentation provided with each package. You can see what commands are

available with the package as well as what documentation you can review. Here are the files delivered with Red Hat 9.0: # rpm -q --filesbypkg vixie-cron-3.0.1-74 vixie-cron /etc/cron.d vixie-cron /etc/rc.d/init.d/crond vixie-cron /usr/bin/crontab vixie-cron /usr/sbin/crond vixie-cron /usr/share/man/man1/crontab.1.gz vixie-cron /usr/share/man/man5/crontab.5.gz vixie-cron /usr/share/man/man8/cron.8.gz vixie-cron /usr/share/man/man8/crond.8.gz vixie-cron /var/spool/cron # rpm -q --filesbypkg crontabs-1.10-5 crontabs /etc/cron.daily crontabs /etc/cron.hourly crontabs /etc/cron.monthly crontabs /etc/cron.weekly crontabs /etc/crontab crontabs /usr/bin/run-parts

SUSE 9.0 delivers the following files with the cron package:

# rpm -q --filesbypkg cron-3.0.1-824 cron /etc/crontab cron /etc/init.d/cron cron /usr/bin/crontab cron /usr/lib/cron cron /usr/lib/cron/run-crons cron /usr/sbin/cron cron /usr/sbin/rccron cron /usr/share/doc/packages/cron cron /usr/share/doc/packages/cron/CHANGES cron /usr/share/doc/packages/cron/CONVERSION cron /usr/share/doc/packages/cron/FEATURES cron /usr/share/doc/packages/cron/MAIL cron /usr/share/doc/packages/cron/MANIFEST cron /usr/share/doc/packages/cron/README cron /usr/share/doc/packages/cron/THANKS cron /usr/share/man/man1/crontab.1.gz cron /usr/share/man/man5/crontab.5.gz cron /usr/share/man/man8/cron.8.gz

cron /var/spool/cron cron /var/spool/cron/deny cron /var/spool/cron/lastrun cron /var/spool/cron/tabs

Listing the files delivered in the package makes it easy to see the differences between distributions.

kcron

A nice graphical front-end utility is available for the crontab command. The kcron utility is part of KDE and is supplied with the optional kdeadmin package. The kcron utility is a simple, intuitive method for users to manage their cron jobs. The English version of the kcron handbook is available at http://docs.kde.org/ en/3.1/kdeadmin/kcron/index.html. To start kcron, choose System Tools, Task Scheduler from the main KDE menu, and you will see the interface shown in Figure 10-1.