Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a crontab which will launch a certain program early in the morning (after I have gone to sleep) and close it again later in the morning (before I wake up). But my iMac will not execute the crontab script while it is asleep.

I see there is some preferences to wake the machine up and make it sleep again at a specified time, but is there a way to do this using the crontab?

share|improve this question

5 Answers 5

up vote 8 down vote accepted

cron doesn't execute while the computer is asleep, so there's no way for you to have a crontab entry to wake the computer. That said you can schedule the computer to wake just a minute or two before your cron task in Preferences >> Energy Saver >> Schedule.

It's also worth pointing out that since Tiger, Apple has moved most scheduled jobs from cron and scripts like init.rc to the launchd process. It provides more detailed (but cumbersome, I think) means of control (through several plist files). It will also automatically run tasks missed because the computer was sleeping when it awakens. Take a look at Apple's Scheduling Timed Jobs page.

share|improve this answer
    
The link is broken. –  retracile Nov 26 '11 at 22:59

You can schedule your Macintosh to wake up in the Energy Saver preference panel. See the Schedule button.

share|improve this answer

You might want to look into Anacron

Anacron runs the periodic daily, weekly and monthly tasks on your Mac even if the machine (a laptop, for example) spends much of its time asleep or switched-off. Anacron silently checks when you reboot and every sixty minutes while the computer is running to see if the various periodic scripts are overdue, and runs them if necessary. The advantage of Anacron over many other solutions to this issue is that it runs as a proper Unix background process, requires no user intervention, and uses the regular periodic scripts.

Another applicaiton that might do the trick is Awaken

share|improve this answer

cron will not run while OSX is in sleep mode.

You may want to look into cronwake (must run through google translate as the site is japanese I believe) and anacron, or you can just use the Energy Saver application to schedule a wake time to run the script, then put it back to sleep.

share|improve this answer

Another way to schedule waking up from sleep is to use pmset:

sudo pmset repeat wakeorpoweron MTWRFSU 03:45:00

launchd cannot wake a computer from sleep, but it does run jobs scheduled during sleep after waking up. If others search for how to do that, you can for example save this plist as ~/Library/LaunchAgents/some.label.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>some.label</string>
  <key>ProgramArguments</key>
  <array>
    <string>say</string>
    <string>a</string>
  </array>
  <key>StartCalendarInterval</key>
  <dict>
    <key>Hour</key>
    <integer>23</integer>
    <key>Minute</key>
    <integer>59</integer>
  </dict>
</dict>
</plist>

Then run launchctl load ~/Library/LaunchAgents/some.label.plist.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.