#!/bin/sh
# While working in console mode (without gdm) this script
# tells you the remaining charge of your laptop battery
#
# Run it along with watch on a separate tty
# $ watch -n 10 ./batmon
#
# (c) Hunterwala, 2009
#
# TODO: check for error levels and buzz using pcspkr mod
# when the charge level decreases beyond that level.
PROC_PATH="/proc/acpi/battery/BAT0"
org_cap=`cat $PROC_PATH/info | grep "last full capacity" | sed "s/ //g" | awk -F: '{print($2)}' | sed "s/mAh//g"`
rem_cap=`cat $PROC_PATH/state | grep "remaining capacity" | sed "s/ //g" | awk -F: '{print($2)}'| sed "s/mAh//g"`
message=`cat $PROC_PATH/state | grep "charging state" | sed "s/ //g" | awk -F: '{print($2)}'| sed "s/mAh//g"`
diff=$(echo "($org_cap-$rem_cap)" | bc)
total_per=$(echo "100-($diff*100/$org_cap)" | bc)
echo "Battery is" $message ":" $total_per"%"
Save this script as
batmon.sh
Change the permissions
chmod a+x batmon.sh
Run it on a separate tty
watch -n 10 ./batmon.sh
No comments:
Post a Comment