#!/bin/sh # # Shuts down the computer when the battery reaches its warning capacity. # # Any modern battery needs to discharge from time to time in order to keep # it in the best possible working state. Since it is annoying to stare at # a screen, only waiting for the "your battery is on low capacity" # message, this script was created. Just run it (as root) and it will # automagically shut down your computer when the battery reaches its # warning capacity. # # By default BAT0 (the main battery) is monitored. If you want to monitor # an other battery pass its name (e.g. BAT1) as the first argument. # # This script is (c) 2010 Robert Weiler . It is # released under the terms of the MIT license. # if [ -z "$1" ] ; then BAT="BAT0" else BAT="$1" fi if [ ! -d "/proc/acpi/battery/$BAT" ] ; then echo "Error: Cannot find the battery in /proc." exit 1 fi BAT_WARN="`grep -E '^design capacity warn' \ /proc/acpi/battery/$BAT/info | cut -c26- | cut -d' ' -f1`" echo "Discharing until $BAT reaches $BAT_WARN mAh charge." while [ /bin/true ] ; do BAT_CAPA="`grep -E '^remaining' /proc/acpi/battery/$BAT/state | \ cut -c26- | cut -d' ' -f1`" if [ $BAT_CAPA -gt $BAT_WARN ] ; then echo "Capacity at $BAT_CAPA mAh. Waiting." else echo "Capacity at $BAT_CAPA mAh. Shutting down." /sbin/shutdown -h now & exit 0 fi sleep 60 done # vim: set sw=4 ts=4 noet ft=sh fenc=us-ascii ff=unix tw=74 :