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

Scripts to enable cron tasks to run on time UNIX
I was frustrated about cron not running because my Mac was asleep late at night so this weekend I wrote a couple of tools to make sure that cron was "on the job" at critical times.

The first is dailyWakeup, a command line program that uses the Power Manager API to schedule a wakeup of the Mac a little before the time for cron to do its work. I also have cron run dailyWakeup to queue the request for the next day. This is probably not for newbies, since the program has to be customized and recompiled for each installation.

The second tool is ShowPMQueue; this program displays all of the events in the Power Manager queue. If the actual executable program is suid'ed to root, then events can be added or deleted from the event queue. This program (properly installed) make it very easy to schedule wakeups, sleeps, boot times and power down times.

Source and a meager discussion are located here: http://homepage.mac.com/levanj/Cocoa

[robg adds: I haven't tested these scripts, and they are clearly not targeted at newcomers to the UNIX side of OS X...]
    •    
  • Currently 1.75 / 5
  You rated: 2 / 5 (4 votes cast)
 
[8,637 views]  

Scripts to enable cron tasks to run on time | 8 comments | Create New Account
Click here to return to the 'Scripts to enable cron tasks to run on time' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Scripts to enable cron tasks to run on time
Authored by: dogboy on Mar 29, '04 11:28:06AM
Get Macaroni. It's shareware and runs these scripts when your Mac wakes up.

[ Reply to This | # ]
Scripts to enable cron tasks to run on time
Authored by: jeremyrh on Mar 29, '04 01:38:44PM

Another option is Xjanitor, which is a Perl script that runs at the interval you set (eg once an hour) in cron and runs whatever clean-up routine is due.



[ Reply to This | # ]
Scripts to enable cron tasks to run on time
Authored by: blalor on Mar 29, '04 11:33:46AM
Wouldn't anacron be much easier?

I took anacron a step further by wrapping it with a script that check to see if I'm on battery or not, and doesn't run if I am. Repairing disk permissions when running on battery at reduced CPU isn't real pretty. :-) I'm using this battery script to check my battery status.

[ Reply to This | # ]
anacron
Authored by: SeanAhern on Mar 29, '04 05:10:24PM

I have to second the suggestion of anacron. Very standard, very useful, and it was designed for this type of thing. Available from fink.

I've set up cron to run anacron every 5 minutes. Thus, within 5 minutes of my computer waking up, my jobs fire. I use it all the time.



[ Reply to This | # ]
Scripts to enable cron tasks to run on time
Authored by: spfolly on Mar 30, '04 08:04:25AM

Thirded, but there is an OS X package which does the whole installation so you don't have to worry about building it yourself:

http://www.alastairs-place.net/anacron.html



[ Reply to This | # ]
Scripts to enable cron tasks to run on time
Authored by: klktrk on Mar 29, '04 02:21:59PM

Yep. XJanitor. Free, and requires just s few bits of command line foo.
http://theapotek.com/teknotes/archives/000040.html



[ Reply to This | # ]
Scripts to enable cron tasks to run on time
Authored by: DavidRavenMoon on Mar 29, '04 04:45:23PM

I used CronniX to set the times to when I have my Mac on.



[ Reply to This | # ]
Scripts to enable cron tasks to run on time
Authored by: Yelsmek on Mar 30, '04 12:40:53AM

Each of the alternative suggestions above will execute cron-type scripts that were not executed while the system slept -- AFTER the system wakes up. This is fine for tasks that are not time dependant, such as the maintenance scripts.

However, none of them have the unique feature the thread creator's tool offers: waking the system at specific times to run the scripts at the regularly scheduled time -- for instance, to record your favorite mp3 talk-radio stream.

The author's dailyWakeup script that employs the power management API to do this is a very useful tool I've been looking for for quite some time.

Thanks.

If I might suggest an enhancement that would eliminate the need for an extra configuration file: examine the crontab file(s) and allow the user to specify which of those events should be scheduled to wake the computer a few minutes beforehand.

P.S. Another annoyance is that the web server ceases to function when the system goes to sleep!



[ Reply to This | # ]