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
Calipso
Member since:
2007-03-13

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

cheers

Reply Score: 4

os
by syphon on Wed 8th Dec 2010 19:55 UTC
syphon
Member since:
2005-07-14

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
Tuishimi
Member since:
2005-07-06

...Thank you!

Reply Score: 4

Script to "wake at" easily
by samueldr on Wed 8th Dec 2010 20:12 UTC
samueldr
Member since:
2006-08-07

Hi!

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:
------------
#!/bin/bash

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
fi

#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:
2006-01-12

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
big_gie
Member since:
2006-01-04

Thanx!
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

Suspend
by vivainio on Thu 9th Dec 2010 09:19 UTC
vivainio
Member since:
2008-12-26

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:
2006-02-15

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

Picture
by Bobthearch on Thu 9th Dec 2010 18:47 UTC
Bobthearch
Member since:
2006-01-27

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

Weird...

Reply Score: 2

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

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
james_parker
Member since:
2005-06-29

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

rdate -s server; hwclock --systohc; rtcwake args; overNightScript.sh

The overNightScript.sh 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 overNightScript.sh 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
Dedoimedo
Member since:
2010-06-21

Blurred on purpose for artistic impression ;)

Reply Score: 1