PDA

View Full Version : [SOLVED] Execute a command when power supply is disconnected?



dementic
May 16th, 2010, 08:49 PM
Is there a way to do that since the computer and OS is aware that the power supply is disconnected.

quadproc
May 16th, 2010, 09:33 PM
Is there a way to do that since the computer and OS is aware that the power supply is disconnected.
It is possible to execute an epilog procedure as a result of a power failure if you have a UPS that can signal the computer when a power loss occurs and if you are running a daemon which watches for the power fail signal. The daemon can then invoke code of your choice.

If you have a very quick executing epilog procedure then you might be able to execute it during the holdup time of the computer's power supply. I would not attempt this without a real time operating system.

quadproc

dementic
May 16th, 2010, 09:40 PM
I was thinking a laptop power supply. That means when the computer switches on battery. Maybe I didn't explained well. Thank you for your answer.

Because I have the problem of hard disk head loading/unloading too frequently when on battery. The hdparm -B passes from 254 to 128 once the cable is disconnected. So I want to execute the command:


(sudo) hdparm -B 254 /dev/sda when the charger is disconnected.

StuartN
May 16th, 2010, 09:50 PM
Is there a way to do that since the computer and OS is aware that the power supply is disconnected.

GKrellM should hook into all that signalling and allow you to run standard procedures or custom scripts: http://members.dslextreme.com/users/billw/gkrellm/gkrellm.html

dementic
May 16th, 2010, 10:28 PM
I was wondering is there was a file with predefined actions like for suspend or hibernate, or maybe a smaller daemon than GKrellM to keep a light system.

dementic
May 17th, 2010, 12:40 AM
Ok I made a script with the help of acpi -a which gives the power status if someone need it :


#!/bin/sh
while [ 1 ]; do
dfds=$(acpi -a)
if [ "$dfds" = "Adapter 0: off-line" ]; then
{
hdparm -B 254 /dev/sda
}
fi
sleep 10
done

Thanks

rmartin16
May 23rd, 2010, 09:55 PM
I think this is the solution you were looking for

http://ubuntuforums.org/archive/index.php/t-875263.html