LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   power outage (http://www.linuxquestions.org/questions/linux-server-73/power-outage-604162/)

blackmamba11 12-03-2007 12:19 PM

power outage
 
How can one tell if your linux server has experienced a power outage. For example, i have 2 servers in a datacenter. If the power goes out, is there a log that will tell me that the power went out unexpectedly?? I am using redhat enterprise 4 advanced server.

polymath69 12-03-2007 12:51 PM

Well, who -b will tell you when the system was last booted; you could have a script check this periodically and email you if it changes.

So something like a combination of the following would email you only on unexpected reboots.

/etc/rc0.d/S30shutdownonpurpose:
#!/bin/sh
touch /deliberateshutdown

crontab entry:
*/5 * * * * /usr/local/bin/check-reboot

/usr/local/bin/check-reboot:
#!/bin/bash

if [ -f /deliberateshutdown ]; then
rm /deliberateshutdown
who -b > /var/run/lastboot
elif ! cmp /var/run/lastboot <(who -b) >/dev/null; then
mail root -s power <<<"There may have been a power outage"
who -b > /var/run/lastboot
fi


All times are GMT -5. The time now is 07:05 PM.