#!/bin/bash # by TeknoHog (of iki.fi) for Fujitsu Siemens Amilo Pro V2020 # Suspends the machine to disk when running low on battery power. LOGFILE=/root/test.log # If we're online, don't bother even if the capacity is low. ONLINE=`cat /proc/acpi/ac_adapter/AC0/state | grep on-line` if [ -n "$ONLINE" ]; then exit; fi # TODO: parse the "%n mAh" part for more robust results, instead of awk CAPA=`grep remaining /proc/acpi/battery/BAT0/state | awk '{print $3}'` LOW=`grep "design capacity low" /proc/acpi/battery/BAT0/info | awk '{print $4}'` # Do something to the numbers before comparison. # If the variables are empty, the evaluation is true :( if [ $((CAPA+2)) -lt $((LOW+1)) ]; then echo Hibernating on `date` >> $LOGFILE echo "capa: " $CAPA >> $LOGFILE echo "low: " $LOW >> $LOGFILE echo "event info:" $@ >> $LOGFILE /usr/sbin/hibernate fi