#!/bin/bash #****************************************************************** # Script: acmon # Author: matt # Purpose: checks if ac power gone from xo and schedules shutdown. # If the ac power is restored and there is a shutdown in progress # then the shutdown will be cancelled # Should be run from /etc/crontab as follows : # 00,10,20,30,40,50 * * * * root /usr/local/bin/acmon # NOTE the cron interval needs to less than the SHTDWNTIME # so that the server picks up if the power is back down # Versions: # 0.1 04/04/08 Initial Matt # 0.2 05/04/08 added -h switch to shudown Matt #****************************************************************** # Length of time before shutdown SHTDWNTIME=15 # if there is no ac power if [ $(cat /sys/class/power_supply/olpc-ac/online) = 0 ]; then # if there no shutdown in progress then schedule on in 15 mins pgrep shutdown >/dev/null 2>&1 if [ $? -ne 0 ]; then shutdown -h $SHTDWNTIME "power failed" >/dev/null 2>&1 & logger -p info "acmon: Shutting down in $SHTDWNTIME minutes due to ac pwr failure" else logger -p info "acmon: No ac power and shutdown already in progress" fi else # if there is ac power and a shutdown in progress cancel it... pgrep shutdown >/dev/null 2>&1 if [ $? -eq 0 ]; then shutdown -c >/dev/null 2>&1 logger -p info "acmon: Cancelling shutdown due to ac pwr restore" fi fi