Click to See Complete Forum and Search --> : Turn power off if computer idle


gregj_be
05-22-2003, 11:12 AM
Hi,

We use a common computer in the house with some fellow students and people tend to forget to turn it off.
I wonder what would be the easiest way to let the computer turn itself off automatically when it is idle for a certain amount of time. We use Mandrake 9.1 but I suppose it does not make much difference.
Any help appreciated!

Greg

quip
05-22-2003, 11:28 AM
I don't think there is an easy way. Check power settings in the Control Center.
However, if most of the people using your computer use it during the day, you could always set up a cron job to shut the system down at say, midnight (or whenever people usually don't use it)

MxCl
05-22-2003, 11:54 AM
I wasn't going to reply since I am no expert here but there is a way, using the apm suite.

It has facilities to power down or off machines after time periods. I never tried it myself since it seemed too much work for too little gain.

scott_R
05-22-2003, 02:39 PM
Never tried this one, but maybe a script running in the background? Something that checks at intervals to see who logged out last, and if a certain amount of time has passed since then, to run a 'shutdown -h now', might work. If you find a good way to do it, share it with others! :)

gregj_be
05-24-2003, 06:54 AM
Hi,

Thanks for the answers. I haven't found anything useful either in cc or in mcc. And 'man apm' doesn't say anything about shutting down the computer.
As I have been thinking: perhaps I could monitor the cpu load and if this drops below 5 or 10% for more than 15 minutes, it could issue a 'shutdown -h now' Question: how do I monitor the cpu load? gkrell shows me a nice chart but how do I access the actual load?

Greg

gregj_be
05-30-2003, 04:35 AM
Hi All,

I posted the same question at an other site (http://www.linuxquestions.org/questions/showthread.php?s=&postid=317580#post317580), and I have received a very useful answer there.
Here is the solution:


#!/bin/sh
# Purpose: check loadaverage and shut down
# Args: none
# Deps: Bash, uptime
# Run from: cron
# written by: unSpawn
# posted at www.linuxquestions.org
# modified by: Gergely Juhasz

load0="0"
load1="10"
uptime | while read i;
do i=( ${i} )
case "${i[4]}"
in 0) if [ "${i[9]:0:1}" -le "${load0}" -a "${i[9]:2:2}" -le "${load1}" ];
then shutdown -h now;
fi;;
*) exit 0;;
esac;
done;
exit $?



"What this does is test for the amount of users active on the system, if there are any it exits. If there are none it will test for the load to be below or equal to 0.10. If it is it will do activate the shutdown command. Tweak the variables load0 and load1 to what your system does for minimal load, then add this as a cronjob to /etc/crontab to run every 15 mins or tweak as you like:
0,15,30,45 * * * * * root /etc/where/you/put/the/file.sh
and make it owned by root only and executable by root only."

It works fine!!!! A great Thank You! to unSpawn who helped me out!!!