#!/bin/sh VER=1.0 TMPFILE=/tmp/.battcheck if [ -f $TMPFILE ]; then echo "Already in progress?" exit fi LOGGER=/usr/bin/logger BAT_INFO=/proc/acpi/battery/BAT0/info BAT_STATE=/proc/acpi/battery/BAT0/state REMAINING=`grep "remaining capacity:" $BAT_STATE | sed -e 's/ //g' | cut -f 2 -d ':' | cut -f 1 -d 'm'` LOW=`grep "design capacity low:" $BAT_INFO | sed -e 's/ //g' | cut -f 2 -d ':' | cut -f 1 -d 'm'` if grep -q discharging $BAT_STATE >/dev/null 2>&1 then touch $TMPFILE if [ $REMAINING -lt $LOW ]; then $LOGGER Battery is extremely low, shutting down in 5 minutes # Alert here sleep 5m if grep -q discharging $BAT_STATE >/dev/null 2>&1 then rm -f $TMPFILE shutdown -hP now Battery is extremely low, shutting down # If you prefer, comment/delete the shutdown line and use my suspend script # /usr/local/bin/suspend hibernate else rm -f $TMPFILE $LOGGER Shutdown avoided, AC has been restored. fi else rm -f $TMPFILE fi fi