10

I would like to run a shell script daily, but not necessarily at a specific time. The computer the script runs on is switched on at irregular times, and no assumptions can be made when that will be.

For that, I would like to get launchd to behave a bit like anacron: It only needs to run the job once a day, at any convenient time.

Most posts I have seen here or on other sites describe things like "running every day at 05:00", which is not helpful for me if the machine is off at that time...

How do I write a launchd plist specifying that behaviour?

0

1 Answer 1

8

Launchd will run your jobs next time the mac wakes from sleep. So if you shut down your mac, this won't work. You will need to put your mac to sleep to get your daily script to run when the mac wakes if the last time it should have run was during the sleep duration.

man launchd.plist:

If the system is asleep, the job will be started the next time the computer wakes up. If multiple intervals transpire before the computer is woken, those events will be coalesced into one event upon wake from sleep.

Or in other words: You don't have to do anything specific, it's the default behavior anyway.

If you also want to run the command once after reboot, add

<Key>RunAtLoad</Key>
<true/>

to your launchd plist.

2
  • Thanks for the reply, but I need an approach that will also work if the machine has been turned off.
    – jstarek
    Commented Aug 13, 2011 at 23:28
  • 2
    Ah, sorry, my mistake. However, at least on Snow Leopard, it's RunAtLoad, not RunAtLaunch -- or am I making the next mistake here? :-)
    – jstarek
    Commented Aug 18, 2011 at 16:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .