Linked by Dedoimedo on Wed 8th Dec 2010 17:40 UTC
Linux Here's the latest in our new series on OS tips from power users: a seemingly trivial task. You have a computer, most likely a laptop, that you wish to keep suspended while you're not working. For example, let's say overnight. At the same time, you wish to run a handful of maintenance tasks, like backups and cleanup, which you don't normally do during the day. So you need a mechanism that will send your machine to sleep, wake it up when necessary, run cron jobs, then send it back to sleep again.
Thread beginning with comment 452803
To read all comments associated with this story, please click here.
Script to "wake at" easily
by samueldr on Wed 8th Dec 2010 20:12 UTC
Member since:


I made a simple bash script to tell my computer to wake at a certain time without much fuss about the time format. It also corrects for a time which seems in the past but actually is in the future.

Here are some use case.
It's 13:00 (01:00 PM)
wake_at 15 #Will wake at 15:00
wake_at 16:45 #Will wake at 16:45
wake_at 8 #Will wake the next morning at 8

This means that when you go to sleep, you can go to a console (or anywhere you can type commands) and simply type the time you want your computer to wake at. Sure, you can't tell it to wake in a week with it, but it's not its intended use; it has a limited scope of 24 hours.

Here's the script:

wake_at=`date --date "$1" +%s`
now=`date +%s`

#Add a full day to the time if it is lesser than now...
#This allows calling `wake_at 8:00` the evening before.
if [ $wake_at -lt $now ]; then
let wake_at=$wake_at+86400

#Then execs rtcwake
exec rtcwake -l -t $wake_at -m no

Hope it helps!

Reply Score: 5

RE: Script to "wake at" easily
by Karitku on Thu 9th Dec 2010 09:21 in reply to "Script to "wake at" easily"
Karitku Member since:

Thanks for extra info, really helped. Hopefully this will become standard feature in OS itself(well distro atleast) with easy UI. In future corporations might want this kind a feature to low down energy use. Having work machines start and shutdown automaticly in certain times would save tons of energy. It's so common to see people just leave PCs open for whole night, doing nothing.

Reply Parent Score: 2