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.
Order by: Score:
nice tip
by Calipso on Wed 8th Dec 2010 19:27 UTC
Member since:

nice tip. Keep these type of articles coming OSNews. Bookmarked for future reference.


Reply Score: 4

by syphon on Wed 8th Dec 2010 19:55 UTC
Member since:

after all these years, OSnews is going to post articles about operating systems, no way ;)

Edited 2010-12-08 19:57 UTC

Reply Score: 4

Useful article...
by Tuishimi on Wed 8th Dec 2010 20:07 UTC
Member since:

...Thank you!

Reply Score: 4

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 UTC 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 Score: 2

Great article!
by big_gie on Thu 9th Dec 2010 02:32 UTC
Member since:

I'll try to use this in my setup. Right now I have an old laptop which on resume will launch an mp3 internet radio. Since it resume from suspend on the press of a key, as soon as the real alarm clock rings, I press a key and I have my real radio.

I think I did not investigated an automatic way of doing it for two reason:
1) Ease changing the wakeup time. I did not know how to do it. Now I do ;)
2) I think I have an issue with the hardware clock. I changed the bios battery but I'm not sure it fixed it. I'll check it back because of your article ;)

Reply Score: 1

by vivainio on Thu 9th Dec 2010 09:19 UTC
Member since:

What if it's a laptop that is configured to suspend when lid is closed - and the lid is closed at the alarm time? Wakeup + suspend immediately?

Reply Score: 2

RE: Suspend
by WereCatf on Thu 9th Dec 2010 09:36 UTC in reply to "Suspend"
WereCatf Member since:

What if it's a laptop that is configured to suspend when lid is closed - and the lid is closed at the alarm time?

When the lid is closed it emits a signal triggering the suspend. But if the lid is already closed when the machine is powered on it won't emit a signal. The system could of course poll for the state of the lid but as far as I know no sane Linux distro handles it that way.

Thus I'd say the system wakes up at specified time and does what it was supposed to, and keeps on running unless you added another suspend command at the end of the jobs.

Reply Score: 2

by Bobthearch on Thu 9th Dec 2010 18:47 UTC
Member since:

OT: What the hell is that picture, someone's bunghole?


Reply Score: 2

RE: Picture
by David on Thu 9th Dec 2010 23:19 UTC in reply to "Picture"
David Member since:

It's a closed eye, though not a very good picture of one.

Reply Score: 1

A slightly better way
by james_parker on Thu 9th Dec 2010 20:16 UTC
Member since:

Why not combine the four cron jobs into one? Something like:

rdate -s server; hwclock --systohc; rtcwake args;

The script should start as soon as the system wakes up from rtcwake.

Or course, since this must run as root, full paths should be used; in addition, an additional rtcwake call will probably be needed to put the machine back to sleep until morning after completes.

This avoids any dependency on implicit timing, and keeps everything together in a logical unit.

Reply Score: 1

Comment by Dedoimedo
by Dedoimedo on Fri 10th Dec 2010 10:21 UTC
Member since:

Blurred on purpose for artistic impression ;)

Reply Score: 1