LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-17-2008, 12:17 PM   #1
cadcrazy
LQ Newbie
 
Registered: Sep 2008
Posts: 12

Rep: Reputation: 0
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
 
Old 09-17-2008, 12:59 PM   #2
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
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.
 
Old 09-17-2008, 01:57 PM   #3
Linville79
Member
 
Registered: Nov 2006
Location: Indiana, U.S.A.
Distribution: Red Hat Enterprise Linux, Fedora, CentOS
Posts: 134

Rep: Reputation: 16
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 01:58 PM. Reason: clarification
 
Old 09-18-2008, 09:01 AM   #4
cadcrazy
LQ Newbie
 
Registered: Sep 2008
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Matir View Post
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.

Can anybody help me regarding this ????
 
Old 09-18-2008, 09:02 AM   #5
cadcrazy
LQ Newbie
 
Registered: Sep 2008
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Linville79 View Post
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.
Lol good idea
 
Old 09-18-2008, 09:05 AM   #6
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
I'm not sure how the system would get a status from the UPS if not running apcupsd. Do some UPSs generate ACPI events or something? Very weird.
 
Old 09-18-2008, 09:12 AM   #7
cadcrazy
LQ Newbie
 
Registered: Sep 2008
Posts: 12

Original Poster
Rep: Reputation: 0
See this if you don't believe me

[img=http://img205.imageshack.us/img205/7019/screenshot1ly7.th.png]

Last edited by cadcrazy; 09-18-2008 at 09:14 AM.
 
Old 09-22-2008, 11:37 PM   #8
cadcrazy
LQ Newbie
 
Registered: Sep 2008
Posts: 12

Original Poster
Rep: Reputation: 0
Can anyone help me ?????
 
Old 09-23-2008, 10:50 AM   #9
234107
LQ Newbie
 
Registered: Sep 2008
Posts: 8

Rep: Reputation: 0
Quote:
Originally Posted by cadcrazy View Post
Can anyone help me ?????
UPS vendor/model? Interfaces available? Documentation?

EDIT: Also read more about Nagios... maybe u will find it useful..
 
Old 10-07-2008, 08:19 AM   #10
cadcrazy
LQ Newbie
 
Registered: Sep 2008
Posts: 12

Original Poster
Rep: Reputation: 0
lol nagios.

I wana write simple script
 
Old 10-07-2008, 08:28 AM   #11
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
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...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto shutdown after power failure the_bloodwalker Linux - Newbie 1 05-13-2008 06:06 PM
set iBook to automatically power-up after power failure peachy Other *NIX 4 04-19-2006 01:44 PM
Unclean shutdown from power failure... filesystem check errors macisaac Linux - General 4 12-26-2003 08:50 PM
Pls help me write script to shutdown pc Alfastation Linux - Newbie 8 11-10-2003 10:39 PM
Batch Script to shutdown the system in the event of power loss scottpioso Linux - Hardware 5 03-12-2003 04:40 PM


All times are GMT -5. The time now is 09:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration