[techtalk] cron.hourly vs cron.daily timing

David Merrill david at lupercalia.net
Tue May 29 16:34:25 EST 2001


On Tue, May 29, 2001 at 01:03:26PM -0700, Nancy Corbett wrote:
> 
> It depends on how the cron is set up. The exact hour of the day is set
> in the crontab file.  You can check it out yourself by entering crontab -e
> at the command line.  It will bring up the list of scheduled cron jobs.
> Below I have an example of how crons are scheduled.  There are 3 cron jobs
> set up in the example for 1am, 2am and 3am, respectively, at exactly the
> hour.  Since there is no designation for month, day or day of the week,
> the cron will run every time the clock turns to 1, 2 or 3am.

I think you're answering the wrong question. I understand the way
the crontab works, and how you schedule them as you wrote below. What I'm
asking about are the system-level cron jobs that aren't in crotabs at
all, but in /etc/cron.hourly/, /etc/cron.daily, /etc/cron.weekly and
/etc/cron.monthly.

You can easily run a script every hour by simply putting that script,
or a symlink to that script, in the /etc/cron/hourly directory. Then
you don't have to mess with crontabs. That's what I was hoping to do,
because it lets me keep all my cron jobs in that one place.

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.

What if I modify the crontab to schedule the four jobs at 15 minute
increments, comme ca:

# run-parts
01 * * * * root run-parts /etc/cron.hourly
15 4 * * * root run-parts /etc/cron.daily
30 4 * * 0 root run-parts /etc/cron.weekly
45 4 1 * * root run-parts /etc/cron.monthly

Does this all make sense? I don't want to have to fudge with the
crontab every time I alter or add a cron job.

> Hope this helps.

Yep, sure did. Thanks!

> Example:
> 
> # Six fields per line, as follows
> #
> #  minute (0-59),
> #  hour (0-23),
> #  day of the month (1-31),
> #  month of the year (1-12),
> #  day of the week (0-6 with 0=Sunday).
> #  command
> 0 1 * * * /test/nancy/bin/cleanlogfiledir      -P /test/nancy/outdir
> 0 2 * * * /test/nancy/bin/cleandatasourcefiles -P /test/nancy/outdir
> 0 3 * * * /test/nancy/bin/cleandatabasetables  -P /test/nancy/outdir
> 
> 
> On Tue, 29 May 2001, David Merrill wrote:
> 
> > I'm configuring webalizer on my machine and am scheduling a cron job
> > to process the web logs. I need to make sure the processing of web
> > logs happens *before* the log rotator. The log rotator is called from
> > a script in cron.monthly, and the log processor is going to be in
> > cron.hourly (for now).
> > 
> > Can anyone tell me whether scripts in /etc/cron.hourly are guaranteed
> > to run *before* those in cron.daily, and .daily before .weekly, etc.,
> > etc.? The manpage for cron doesn't say anything about it.
> > 
> > TIA,
> > 
> > -- 
> > Dr. David C. Merrill                     http://www.lupercalia.net
> > Linux Documentation Project                   david at lupercalia.net
> > Collection Editor & Coordinator            http://www.linuxdoc.org
> >                                        Finger me for my public key
> > 
> > System going down at 1:45 this afternoon for disk crashing.
> > 
> > _______________________________________________
> > techtalk mailing list
> > techtalk at linuxchix.org
> > http://www.linux.org.uk/mailman/listinfo/techtalk
> > 

-- 
Dr. David C. Merrill                     http://www.lupercalia.net
Linux Documentation Project                   david at lupercalia.net
Collection Editor & Coordinator            http://www.linuxdoc.org
                                       Finger me for my public key

Real Programmers don't write in PL/I.  PL/I is for programmers who can't
decide whether to write in COBOL or FORTRAN.




More information about the Techtalk mailing list