How to change the time anacron runs.

Well this one took me a while to figure out, so I thought I’d blog about it in case I could save someone else some time. Anacron is installed on desktop / laptop orientated distributions as they’re often switched off. It basically makes sure the daily, weekly and monthly cron jobs are run by checking the time they were last run, and running them if they weren’t run in the last day, 7 days or 30 days respectively. It will also check these when the machine is rebooted. So it makes sense on machines that are rebooted frequently.

However I have a server where it is also installed, alongside cron, and I wanted to change the time logwatch ran every day. My first attempt was to simply change the times in /etc/crontab, which contained lines like this
25 00    * * *    root    test -x /usr/sbin/anacron || ( cd / && run-parts –report /etc/cron.daily )
Changing the time was ineffective, although I gather that if I’d removed anacron (or specifically the file /usr/sbin/anacron ) then this approach would have worked.

My research let me next to the /var/spool/anacron directory where there are three timestamp files cron.daily, cron.weekly and cron.monthly. I experimented with changing the time on these to fool anacron into running earlier in the day. This was also ineffective.

Hmm. Finally I found the solution, which kinda makes sense, but is well hidden. In /etc/cron.d/ there is a file which runs anacron containing the line
30 23    * * *   root    test -x /etc/init.d/anacron && /usr/sbin/invoke-rc.d anacron start >/dev/nul

Changing the time on this will make anacron run at your chosen time, and you’ll have your logwatch report before breakfast.

 

1 thought on “How to change the time anacron runs.

Leave a Comment