cron/anacron

Alan McKinnon alan at linuxholdings.co.za
Wed May 10 19:21:29 UTC 2006


On Wednesday 10 May 2006 03:36, Frank McCormick wrote:
>   Seeing all the messages here about cron/anacron reminded me of a
> question - how do I check to see if a job is being run? Anacron
> checks the timestamps of files., but which files. I find the whole
> cron/anacron thing very confusing. Why doesn't ubuntu use software
> that works on all machines, those that are up all the time and
> those which aren't ?

cron is a really good tool. You tell is to do something at 12 midnight 
and it does it. The problem comes in when the machine is switched off 
at midnight.

There are a few classes of task that cron could do (off the top of my 
head):
- stuff that must run eg critical backups
- stuff that ought to run but isn't a hassle if it's late eg updatedb
- stuff that is nice to run but who cares if it doesn't eg fetching 
mail (you'll just get it all at the next scheduled cron)

cron was designed to run on machines that are up all the time. No sane 
developer is going to try and extend it - it works, it works well and 
it ain't broke. To handle the second case, someone developed anacron 
(anachronistic cron). Here's what it does: it runs periodically 
looking for tasks that have to run once within a time interval and if 
they have not already run, runs them. On my machine, updatedb runs 
daily at 4am. Say I switch the machine off overnight and start it at 
7:30am. At 8am anacron will run and discover that it missed updatedb 
at 4am, and run it anyway.

There is no problem with cron and anacron, the problem is that you 
have not thought it through. How does anacron know when to run, and 
what starts it? Easy! It is run once an hour... from cron! Once an 
hour the system checks for tasks that were skipped.

cron's config file is /etc/crontab
anacron's config file is /etc/anacrontab
The /etc/cron.*ly files have nothing whatsoever to do with cron or 
anacron. They are config files for run-parts (a convenient way to run 
several scripts rather than individual cron entries for each.
Both cron and anacron run run-parts to do their thing.

-- 
If only me, you and dead people understand hex, 
how many people understand hex?

Alan McKinnon
alan at linuxholdings dot co dot za
+27 82, double three seven, one nine three five




More information about the ubuntu-users mailing list