Power off after a certain time of inactivity in Ubuntu (using the activiation of a screensaver to do it)

Reece Arnott <[email protected]>
Newsgroups gmane.org.user-groups.linux.dunedin.general
Message-ID <[email protected]>
Rob was asking for a way to save power by turning off machines that had 
been inactive for a certain number of hours in Ubuntu.

The key thing to realise is that sensing inactivity is what screensavers 
do so... sudo apt-get install xscreensaver if it isn't already installed 
and do the following:

1) create an executable script file from the text file shown here: 
https://gist.github.com/chrisyco/988104 (this is a wrapper to give you 
the options to suspend, hibernate, restart, or shutdown). This is 
optional if you are only going to ever want to shutdown.

2) Run xscreensaver-demo to create a ~/.xscreensaver prefs file if it 
doesn't already exist.

3) Edit the ~/.xscreensaver file.

The important thing is to insert the following line immediately under 
the line that says "programs:       \":
"Shutdown"     /absolute/path/to/power.sh shutdown \n\

The other options below can either be set while you're editing the file 
anyway, or via the GUI by running xscreensaver-demo:
timeout:    2:00:00 # This is the time of inactivity to wait hh:mm:ss
mode:        one # So only one screensaver is run. Note that if you ever 
set this back to cycle through random screensavers you should take out 
the above Shutdown screensaver :-)
selected:    0 #which screensaver is run, if the shutdown script is the 
first one listed under programs then it will be screensaver 0

If you are *only* going to shutdown you don't need to power.sh script, 
instead you can replace the reference to it above with the following line:
"Shutdown" dbus-send --system --print-reply 
--dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager 
org.freedesktop.ConsoleKit.Manager.Stop \n\

(I have tested this on Ubuntu 13.04 and it works. There may be minor 
variations in the older versions so YMMV)

-- 
"Believing men would act in their own interest was not cynicism, it turned out, but sheerest optimism; in reality men do not meet so high a standard."
-- Harry Potter and the Methods of Rationality (Chapter 84)
http://hpmor.com/

Reece Arnott
Dunedin
New Zealand


_______________________________________________
DunLUG mailing list
[email protected]
http://lists.ethernal.org/listinfo/dunlug
DunLUG Wiki - http://dunlug.kallisti.net.nz/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.