#!/bin/sh getval() { case $1 in lastfull) fld=acpibat0.watthour0 ;; remain) fld=acpibat0.watthour3 ;; rate) fld=acpibat0.power0 ;; power) fld=acpiac0.indicator0 ;; esac sysctl -n hw.sensors.$fld | cut -d' ' -f1 } for v in remain lastfull rate power; do eval $v=`getval $v` done # echo $remain $lastfull $rate $power percent=`echo "100*$remain/$lastfull"|bc -l|cut -d. -f1` case $rate in 0.0*) rate=0 ;; esac case $power in Off) printf "AC Offline: Battery remaining %5.1f%%\n" $percent if [ x"$rate" = x"0" ]; then echo Unknown lifetime else life=`echo "$remain/$rate"|bc -l` hour=${life%.*} dmin=${life#*.} min=`echo "0.$dmin * 60" | bc -l | cut -d. -f1` printf "Discharging at %.2f(%.2f/%.2f) - ${hour:-0}h%02dm to go\n" $rate $remain $lastfull $min fi ;; On) printf "AC ONline: Battery remaining %5.1f%%\n" $percent if [ x"$rate" = x"0" ]; then echo "Last full capacity: ${lastfull}Wh" else tf=`echo "$lastfull - $remain"|bc -l` tofull=`echo "$tf/$rate"|bc -l` hour=${tofull%.*} dmin=${tofull#*.} min=`echo "0.$dmin * 60" | bc -l | cut -d. -f1` printf "Rate $rate to $tf ($remain/$lastfull) - " printf "${hour:-0}h%02dm to full\n" $min fi ;; esac # hw.sensors.acpibat0.volt0=11.40 VDC (voltage) # hw.sensors.acpibat0.volt1=11.75 VDC (current voltage) # hw.sensors.acpibat0.power0=6.59 W (rate) # hw.sensors.acpibat0.watthour0=46.74 Wh (last full capacity) # hw.sensors.acpibat0.watthour1=2.34 Wh (warning capacity) # hw.sensors.acpibat0.watthour2=0.20 Wh (low capacity) # hw.sensors.acpibat0.watthour3=30.78 Wh (remaining capacity), OK # hw.sensors.acpibat0.watthour4=48.10 Wh (design capacity) # hw.sensors.acpibat0.raw0=1 (battery discharging), OK # hw.sensors.acpibat0.raw1=24 (discharge cycles)