Want to write shutdown script in case of power failure
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Want to write shutdown script in case of power failure
Hello World
I have apc ups. Tried my luck with apcupsd on Ubuntu/Fedora but failed.I want to know how write a simple script to shudown pc in case of power cut after predefined time and how to run that script as a daemon.
Please help
So you want to monitor your power without apcupsd? Then you'll need to implement APC's protocol in your script to poll the UPS for power status. Seems like it would be easier to use apcupsd to me -- I have it running on 3 machines.
Distribution: Red Hat Enterprise Linux, Fedora, CentOS
Posts: 134
Rep:
Or... if you want to just hack something together... you can write a script to ping your router or another machine (not connected to ups) every 3 to 5 min, and then if it fails twice, have it run your shutdown commands.
Obviously, this is less robust (meaning that it will shutdown if the network connection fails or that other machine gets turned off), but in the event of a power outage (if that's all you're concerned about), it would work.
Last edited by Linville79; 09-17-2008 at 12:58 PM.
Reason: clarification
So you want to monitor your power without apcupsd? Then you'll need to implement APC's protocol in your script to poll the UPS for power status. Seems like it would be easier to use apcupsd to me -- I have it running on 3 machines.
I had some bad luck with Apcupsd on Ubuntu/Fedora. Tried many times but not able to make it run.
And no there is no need to study/implement Apc protocol as every distro come with some generic power management. If I switch off mains and in terminal i get message Pc running on battery power. So only thing i need is to capture this event and start countdown before shutting down.
Or... if you want to just hack something together... you can write a script to ping your router or another machine (not connected to ups) every 3 to 5 min, and then if it fails twice, have it run your shutdown commands.
Obviously, this is less robust (meaning that it will shutdown if the network connection fails or that other machine gets turned off), but in the event of a power outage (if that's all you're concerned about), it would work.
Again, why not just use apcupsd's ability to invoke scripts on UPS on/off? You're obviously running it as you posted a screenshot of its output above...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.