#!/bin/sh for battery in /proc/acpi/battery/BAT* do BATT=`basename $battery` STATE=$battery/state INFO=$battery/info if [ ! -e $STATE -a ! -e $INFO ] then continue; fi ( for y in $STATE $INFO do if [ -e $y ] then cat $y fi done ) | awk ' /present rate:/ { rate = $3; } /remaining capacity:/ { cap = $3; } /design capacity:/ { dcap = $3; } /design capacity warning:/ { warning = $4; } /charging state:/ { charging = $3; } /capacity state:/ { state = $3; } END { action = "remaining" if ( charging == "charging" ) { action = "to charge"; timeleft = ( dcap - cap ) / rate; } else { timeleft = ( cap - warning ) / rate; } percent = cap * 100 / dcap; mins = ((timeleft * 100) % 100) * 60 / 100; hours = ((timeleft * 100) - ((timeleft * 100) % 100)) / 100; printf("Battery '$BATT' %s, %d%% full, %s, %d:%02d %s.\n", state, percent, charging, hours, mins, action); }' done