#!/bin/sh # get charging state CHARGINGSTATE=`cat /proc/acpi/battery/BAT1/state | grep "charging state:" | sed -e "s/charging state: //"` # exit if AC adapter is present if [ $CHARGINGSTATE == "charging" ]; then exit fi # get remaining capacity REMAININGCAPACITY=`cat /proc/acpi/battery/BAT1/state | grep "[0-9] mAh" | sed -e "s/remaining capacity: //" -e "s/ mAh//"` # hibernate if remaining battery capacity is below 300 mAh if [ $REMAININGCAPACITY -lt "300" ]; then /usr/local/sbin/hibernate fi