Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Run missed cron jobs using anacron UNIX
On PowerBooks and other computers that dont stay on overnight, periodic system maintence jobs run by cron don't run, since they are normalliy scheduled for off-use times like 3am. This means things like your locate.db doesn't get updated and your ever-growing system logs never get truncated. You can manually force these to run yourself using periodic, as was discussed in a previous hint.

Another option is to use the unix utility anacron to automatically do this. anacron is a daemon that automatically starts at boot and watches the cron jobs you have scheduled for daily,weekly, and monthly activities. When it notices that cron has failed to perform a scheduled activity (presumably because the computer was asleep), anacron forces the job to run the next time the computer is awake.

It's easy to install using fink, but you must create a configuration file before it will work. One caution: the standard unix documentation for anacron is not quite appropriate for OS X, so be sure to read the straightforward step-by-step Mac-specific documentation found in /sw -> share -> doc -> anacron -> README.Fink

anacron anacron tries to be polite about how it runs its catch-up jobs. For example, it can be set to wait a decent period after you wake your computer before it tries to run a job, and it can be set not to schedule pending jobs so they don't all run at once. For most people, using anacron is simply a matter of installing it with fink, uncommenting a few lines in the default config file and forgetting it: no tweaking ever. You don't need to be a Unix guru; the README.Fink tells you explicity which lines to uncomment to turn it on.

However there is one situation I've had with anacron that I now know how to fix. Sometimes, like when I'm giving a presentation, I want to make sure that anacron does not suddenly come to life, hitting the disk intensively. There are two things you can do: one is you can turn off anacron, which will stay off until you reboot or restart it. Alternatively, you can lie to it and tell it the cron jobs just ran. here's how:

To stop anacron gracefully send it a SIGUSR1 signal


sudo killall -SIGUSR1 anacron
To restart it later without rebooting

sudo anacron -s
You can combine these into a single script to turn it off for just two hours like this

sudo -b sh -c  'killall -SIGUSR1 anacron; sleep 7200; anacron -s'
Alternatively, to "lie" and fake the timestamps to the current date:

sudo anacron -u
Note that once anacron actually starts running a cron job, it's not advisable to stop it in progress. All above commands are polite and will not stop a running cron job from finishing. So be sure to invoke a desired pause in anacron ahead of time.
    •    
  • Currently 1.25 / 5
  You rated: 2 / 5 (4 votes cast)
 
[20,296 views]  

Run missed cron jobs using anacron | 9 comments | Create New Account
Click here to return to the 'Run missed cron jobs using anacron' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Run missed cron jobs using anacron
Authored by: defpo on Nov 17, '03 12:23:39PM

I couldn't get anacron running properly even with the OSX specifc info, but found this <http://www.alastairs-place.net/anacron.html> and it seems to work fine.



[ Reply to This | # ]
Run missed cron jobs using your fingers
Authored by: yellow on Nov 17, '03 02:41:56PM

Into zee Terminal, typa wiz your fingers:

sudo periodic daily weekly monthly

Voila! Zee scripts, zhe run!



[ Reply to This | # ]
Yeah, that works.
Authored by: porkchop_d_clown on Nov 17, '03 03:01:49PM

On the other hand, you can use anacron and not actually have to be a human alarm clock anymore.

---
Everyone loves a clown, but no one will lend him money!



[ Reply to This | # ]
Run missed cron jobs using your fingers
Authored by: dogcow43 on Oct 27, '04 02:09:56PM

Thank You!! I knew it was simple to force the scripts, but had a damned hard time finding exactly how.

"Keep It Simple Stupid"

Thanks again.



[ Reply to This | # ]
anacron is a huge win.
Authored by: porkchop_d_clown on Nov 17, '03 03:03:33PM

I really don't know why Apple doesn't make it a standard part of the OS; very few home machines are left running 24x7.

---
Everyone loves a clown, but no one will lend him money!



[ Reply to This | # ]
Run missed cron jobs using anacron
Authored by: Felix on Nov 17, '03 03:07:47PM

Another option (although it won't automatically run delinquent cron jobs the next time the computer is turned on) is to use CronniX to change the cron job times to something more agreeable.



[ Reply to This | # ]
Run missed cron jobs using anacron
Authored by: klktrk on Nov 17, '03 03:11:20PM

Or, you can just use XJanitor. You'll need to modify the crontab in the terminal, but there's a very easy to follow user's guide. What's nice about this, too, is that it can send you e-mail or just log messages with statements about the maintenance tasks.

<http://theapotek.com/teknotes/archives/000012.html>

Evidently, the developer is working on a version which will allow you to turn maintenance tasks for a specified period of time, as well as a feature which will check for battery usage before running scripts.



[ Reply to This | # ]
Run missed cron jobs using anacron
Authored by: bassmaster_jeff on Nov 17, '03 05:17:17PM

You can also use MacJanitor to perform the same.

You just need to launch the program, but there are other apps elsewhere that can auto-run at a particular time.

http://personalpages.tds.net/~brian_hill/macjanitor.html



[ Reply to This | # ]
Run missed cron jobs using Macaroni
Authored by: Ledrage on Nov 18, '03 10:09:59AM

Macaroni also does this task very well with an easy gui.



[ Reply to This | # ]