Created
December 5, 2011 13:45
-
-
Save djgraham/1433626 to your computer and use it in GitHub Desktop.
Bash script for linux to show you how worn your battery is
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
bats=`ls /proc/acpi/battery/`; | |
for bat in $bats;do | |
remain=`cat /proc/acpi/battery/$bat/{info,state}|grep remaining|grep -o "[0-9]\+"` | |
full=`cat /proc/acpi/battery/$bat/{info,state}|grep full |grep -o "[0-9]\+"` | |
descap=`cat /proc/acpi/battery/$bat/{info,state}|grep "design capacity:" |grep -o "[0-9]\+"` | |
rate=`cat /proc/acpi/battery/$bat/{info,state}|grep "present rate:" |grep -o "[0-9]\+"` | |
state=`cat /proc/acpi/battery/$bat/{info,state}|grep "charging state:" |grep -o "[a-z]\+$"` | |
echo $state; | |
lostcap=$((((descap-full)*100)/descap)); | |
echo "Lost Capacity:" $lostcap"%" | |
percfull=$(((remain)*100/full)); | |
echo "Percent Full: " $percfull"%" | |
if [[ "$rate" -ne 0 ]]; then | |
if [[ "$state" = 'discharging' || "$state" = 'charged' ]]; then | |
timeleft=$((((remain)*60)/rate)) | |
echo "Time left to run: "$timeleft" minutes" | |
else | |
timeleft=$((((full-remain)*60)/rate)) | |
echo "Time left to full: "$timeleft" minutes" | |
fi | |
fi; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment