Mystified by crontab/anacrontab
Timothy Murphy
gayleard at eircom.net
Mon Mar 1 22:32:57 UTC 2010
Robert Nichols wrote:
>> I'm trying to understand how cron works nowadays.
>> I've been comparing my Fedora-12 laptop
>> with my CentOS-5.4 desktop,
>> and am slightly baffled by the difference between them.
> In CentOS 5, anacron is started by init on entry to any of runlevels
> 2-5. The anacron process checks /var/spool/anacron to see if there
> are any overdue jobs, runs (after a delay) any that are needed, and
> then terminates. As long as the system is up, scheduled jobs are
> handled by cron via the "run-parts" lines in /etc/crontab. The
> "0-anacron" jobs in each of the cron.{hourly,daily,weekly,monthly}
> directories do nothing but update the timestamp in /var/spool/anacron
> so that the next time you boot (or change runlevels) anacron can
> see whether anything needs to be done.
>
> The situation in Fedora 12 is a bit more complex. Once an hour,
> as instructed by /etc/cron.d/0hourly, the cron daemon will run all
> the jobs in /etc/cron.hourly and the first of those is the
> 0anacron job that will, if you are running on AC power, start an
> anacron process to run any needed {daily,weekly,monthly} job.
> It's done that way to provide a centralized place for checking
> that the machine is not running on battery and for adding random
> delay to the starting of jobs, as some of those might be sending
> data to a central server and you don't want all the machines on
> your network to do that simultaneously.
>
> Hope that clarifies things.
Yes, thanks.
I've added the two "logger" lines from Fedora run-parts to CentOS:
----------------------------------------
logger -p cron.notice -t "run-parts($1)[$$]" "starting $(basename
$i)"
if [ -x $i ]; then
$i 2>&1 | awk -v "progname=$i" \
'progname {
print progname ":\n"
progname="";
}
{ print; }'
logger -i -p cron.notice -t "run-parts($1)" "finished $(basename
$i)"
----------------------------------------
Now all cron actions are recorded in /var/log/cron ,
both those in /etc/cron.d/ and those in /etc/cron.hourly, etc,
which seems more logical to me.
--
Timothy Murphy
e-mail: gayleard /at/ eircom.net
tel: +353-86-2336090, +353-1-2842366
s-mail: School of Mathematics, Trinity College, Dublin 2, Ireland
More information about the users
mailing list