[olug] Forcing cron.daily to run

Christopher Cashell topher-olug at zyp.org
Fri Aug 11 16:23:31 UTC 2006


At Thu, 10 Aug 06, Unidentified Flying Banana Dave Thacker, said:
> A little follow up on this one.  Our original goal was to have logrotate run 
> daily at midnight, because we do some statistical reporting out of the logs 
> on our booking engines.   We found that logrotate was run by cron.daily, 
> which in turn was triggered by checking the timestamp 
> of /var/spool/cron/lastrun/cron.daily, and firing if the file was more than 
> 1440 minutes old.  Or so we thought.   I ran touch -t on lastrun/cron.daily 
> in an effort to force cron.daily to run.  It didn't work.  

A few notes for greater control of when things are run from cron. . .

Most Linux distributions (particularly those making use of the
ubiquitous vixie cron) control the running of
cron.[daily|hourly|weekly|etc] from /etc/crontab.  There is usually a
line in there that specifies exactly what time you want to run each
directory's files.  If you change that, you can change when they run.
For example, one box has the following line in /etc/crontab:

02 4 * * * root run-parts /etc/cron.daily

Causing everything in /etc/cron.daily/ to be run just after 4am.  If you
want to have all of them run at midnight, just change it to:

02 0 * * * root run-parts /etc/cron.daily

Alternately, if you want finer grained control than that, you can move a
service to /etc/cron.d and control when it runs separately from
everything else.  For example, on one of my systems the
/etc/cron.daily/logrotate file contains:

---/etc/cron.daily/logrotate---

#!/bin/sh
[ -x /usr/sbin/logrotate ] && /usr/sbin/logrotate /etc/logrotate.conf

-------------------------------

If you wanted to run just this command at a specific time, you could
move /etc/cron.daily/logrotate to /etc/cron.d/logrotate and then edit it
to contain:

0 0 * * *  root [ -x /usr/sbin/logrotate ] && /usr/sbin/logrotate /etc/logrotate.conf

Now logrotate will be run at exactly midnight every night, without any
changes to any other things.

[Snip.]

> DT

-- 
| Christopher
+------------------------------------------------+
| Here I stand.  I can do no other.              |
+------------------------------------------------+




More information about the OLUG mailing list