#!/usr/local/bin/bash
CRITICAL=20
STATCMD='acpiconf -i 0'
LOOPDEL=30
while true
do
REMCAP=`$STATCMD | sed -n 's/Remaining\ capacity:[^0-9]*\([0-9]*\)[^0-9]*/\1/p'`
if [ $REMCAP -le $CRITICAL ]
then
<halt or suspend command>
fi
sleep $LOOPDEL
done
set -- `sysctl -n hw.acpi.acline hw.acpi.battery.life`
You could suspend instead of shutting it downIf I were you, I'd run a cron job that spat out a desktop notification (vianotify-send
) reminding me to check my battery life every ten minutes. I refuse to believe anyone actually appreciates having their computer shut off when they're in the middle of doing something.
How can I setup a cron job to use your script?You can run a shell script either via cron or just adding a loop with sleep in the script itself, e.g.:
Code:#!/usr/local/bin/bash CRITICAL=20 STATCMD='acpiconf -i 0' LOOPDEL=30 while true do REMCAP=`$STATCMD | sed -n 's/Remaining\ capacity:[^0-9]*\([0-9]*\)[^0-9]*/\1/p'` if [ $REMCAP -le $CRITICAL ] then <halt or suspend command> fi sleep $LOOPDEL done
You could suspend instead of shutting it down
How can I setup a cron job to use your script?
sysutils/battray is also a nice tool (disclaimer: I am the author, so of course I'm going to say that ;-)).