[techtalk] cron.hourly vs cron.daily timing

Magni Onsoien magnio at pvv.ntnu.no
Tue May 29 23:41:45 EST 2001


David Merrill:
> Oh, wait. Brain fart. /etc/cron.* don't run by magic. They are
> executed via /etc/crontab which holds:
> 
> # run-parts
> 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
> 
> So, cron.hourly runs on the 1st minute of every hour, cron.daily
> runs the 2nd minute of the 4th hour (which would be after the hourly),
> the weekly runs the 22nd minute of the 4th hour on Sundays, and the
> monthly runs the 42nd minute of the 4th hour on the 1st of each month.
> 
> It appears the answer to my question is yes, they always run
> hourly->daily->weekly->monthly. Assuming that once cron launches a job
> it waits for it to finish before launching the next job. But it doesn't
> make sense for cron to halt and wait on a job to finish, because a job
> that goes into an endless loop would then halt all other cron jobs.
> Cron just *has to* run the jobs asynchronously when their execution time
> comes. So I need to alter the times my jobs run to ensure the hourly
> jobs have time to complete before the daily jobs start.

(This goes for RedHat; I have found no documentation of it (and I don't
wanna read code now) but experienced it on RedHat.)

The problem is that each part in the /etc/cron.{hourly,daily,weekly,monthly}
is run in order - i.e. the first job (script) (starting with the lowest
letter/number) will finish before the next job starts. So if you fex.
happens to do some heavy backup (like backing up 100GB to another disk)
in a script starting with b, then this huge job (taking maybe 15 hours)
will finish before the next job (a script starting with c) starts. Or if
you run two scripts 'logparse' and 'logrotate' the logs will be parsed
before they are rotated, which may or may not be right - but if you
later consider 'parse_www_logs' to be a more intuitive name of the
'logparse'-script, the jobs are suddenly run in opposite order, which is
probably wrong.

So you can't be sure that the hourly job is finished before the
weekly/monthly one, even though it starts before, since the daily job
could be hanging due to something.

I don't know what the right way to avoid this is - I ended up using the
regular crontab(1) for my backupjob, and /etc/crontab w/ run-parts only
for smaller scripts that I am sure will finish in time.


Magni :)
-- 
sash is very good for you.




More information about the Techtalk mailing list