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've got my Mac to wake up during the night and run an rsync to back it up. This is configured through Energy Saver > Schedule.

However it seems that it's going back to sleep before it can get anything done, so I need to stop it sleeping during the execution of the bash script that rsync runs from.

I figured the best way (if it's possible) is to issue a command to set the sleep timeout to "Never" or a very long timeout before it rsyncs and then back to normal once it's complete. Is there a better solution for doing this?

share|improve this question
    
Should be on superuser? –  Kimvais Jan 22 '10 at 11:45
add comment

migrated from stackoverflow.com Jan 22 '10 at 12:48

This question came from our site for professional and enthusiast programmers.

2 Answers

Try

man pmset

:-)

share|improve this answer
add comment

It's buried in the manual page, but pmset has a very simple mode for preventing sleep. If you execute the command pmset noidle your Mac will be kept awake until that process is killed. Here is how to use it in a script:

# launch process to prevent sleep and move it to the background
pmset noidle &
# save the process ID
PMSETPID=$!

... do stuff here ...
... don't fall asleep ...
... watch out for that tree!
... ok we're free and clear now ...

# kill pmset so the computer can sleep if it wants to
kill $PMSETPID

This is better than using pmset to change your sleep settings, which requires root access and (assuming you want to be a good citizen) some way of detecting the current settings and changing them back when you're done.

share|improve this answer
add comment

Your Answer

 
discard

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