Autoit

Autoit

Κυριακή 19 Φεβρουαρίου 2012

Power Server using Linux Bash

We all have heard of various types of servers (mail server, DHCP server etc...), but what is a "Power Server"? Well the answer is simple. Power server is a script that checks the power (AC 230V) on our home or office and shuts down network computers when there is a power failure. Of course someone could say "isn't that feature allready embedded on a simple-local UPS ?"
Well ... Of course it is, but think all the trouble to set it correctly.
First you have to connect the UPS with each PC usually with a USB cable, then you must install the UPS software on every PC, after that you have to configure that software on every single computer on the network and last but not least, every now and then you must check that the software is running correctly and it has not been disabled by the PC's user because he or SHE didn't know what that tray icon is for.
All you need to run the "Power server" is a cheap laptop which is running a version of linux with "bash shell" and has a network connection (practicaly every laptop of the last 5 years). All the computers and network switches must be powered from UPS. The laptop that serves as the "Power server" must NOT be powered from UPS.

The way the script works is simple:
-------------------------------------------------------------------------------------------------
First check if the AC adapter is off-line
__if so wait for 30 sec and check again (in order to avoid action in a brief loss of power)
____if power is down after second check then
______send the shutdown command to the network computers
______log the power loss and
______store that the computers have been shutdown
____if power is on-line the second check then
______log it as a brief lose of power
If the ac-adapter is on-line then
__if the computers have been previously shutdown then
____wake the computers that must be allways on-line (NAS, server etc...)
____log that the power is on-line again and
____store that the computers have not been previously shutdown
__if the computets have not been previously shutdown
____display an "everythink is OK" message
-------------------------------------------------------------------------------------------------
Of course you can add some extra features like sending you an email on power fail and thinks like that.

You can Download the code from here:
-untar the file, make the necessary changes to the file remote_server.sh according your network using vi or nano and then execute the file remote_server.sh

I am sure that there are better and more sophisticated ways of doing all this power management but i had a good time exploring bash shell coding.
Always remember "Coding can be fun when you do it your own."


Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου