Benches macOS

7

Wake Mac from sleep to run script in cron…

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

I wrote my own backup script and run it via root's crontab. It is a simple find -newer command piped into a tar command. Nothing flashy like Time Machine. No GUI.

Currently it looks like I need to stay logged in all the time with X11 running for crontab to work. Can I get around this somehow?

Ideally I would prefer the Mac to wake up from sleeping and run my backups nightly.

7 replies

Sign in or join Beachball Help to reply.

  1. 0

    Jun T.

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Did you try System Preferences > Energy Saver > Schedule..?

    I have never tried this by myself so I'm not sure whether it works as expcted or not.

  2. 0

    Camelot

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    You don't need to be logged in from cron entries to work, but the machine can't be asleep.

    If it's asleep, no processes are running, including cron, so it can't fire off your script.

    Your best option is to use Energy Saver to wake your machine a few minutes before you want the backup to run. Your script can sleep the machine when it's finished.

    An alternative that might work would be
    at. From memory, when the machine wakes,
    at will invoke scripts that should have run when the machine was asleep.

  3. 0

    foilpan

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    and X11 doesn't need to be running for the crontab entries to work. your machine just needs to be awake. try "at" or create a launchd plist to run the script upon machine wake, and you should be all set.

  4. 0

    Boyd

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Long time since I posted here. For my macs, I installed anacron from Fink - it will run the 1/day, 1/week, etc. scripts anytime it is awake. Works like cron, but its for those scripts that you don't care when they run during the day.

    I also moved the cron.daily scripts to run under anacron so the admin clean-ups always get run.

    Now my G5 and my wife's iBook both get regular backups and I can worry about one thing less. You can read about it at
    http://www.macosxhints.com/article.php?story=20031111110802488

    Boyd

  5. 0

    Hawaiian Scuba Dude

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    This is a step in the right direction. I will put the computer to sleep and wake it up on time for the next backup.

  6. 0

    Hawaiian Scuba Dude

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    How do I put the mac to sleep from a sh script?

  7. 0

    Hawaiian Scuba Dude

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Thanks for the advice. I will look into the anacron command. For now, I have a means to support the functionality of that command.