LinuxQuestions.org

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

blackmamba11 12-03-2007 11:19 AM

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 11:51 AM

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 02:04 PM.