You are not logged in.
Here's something I threw together last night, to report on the battery at the command line. It uses /proc/acpi/battery. My battery is C11F, just substitude your own.
It takes (remaining capacity) / (design capacity) to get the percent left, and it takes the (discharge rate) / (remaining capacity) to get approximate life. If the rate is zero (which mine reports as when plugged in) it says the battery is charging.
I don't know if this will work for other people, or if different batteries give different times of information to ACPI.
#!/bin/bash
current=`grep remaining /proc/acpi/battery/C11F/state | tr -d A-z | tr -d " " | tr -d :`
total=`grep "design capacity:" /proc/acpi/battery/C11F/info | tr -d A-z | tr -d " " | tr -d :`
rate=`grep "present rate:" /proc/acpi/battery/C11F/state | tr -d A-z | tr -d " " | tr -d :`
percent=`bc << EOF
100.0 * $current / $total
EOF
`
if [ $rate -eq 0 ]; then
echo $percent'%, charging'
else
hours=`bc << EOF
(1.0*$current) / (1.0*$rate)
EOF
`
minutes=`bc << EOF
60.0 * $current / $rate - $hours * 60
EOF
`
echo $percent'%, '$hours':'$minutes
fi
You can also try the 'acpi' pkg, which does exactly the same thing .
Offline
You can also try the 'acpi' pkg, which does exactly the same thing .
Considering the acpi package is only dated a few days ago, I don't feel too bad about not knowing about it.
BTW, here's an update I did to my script. This one prints minutes less than 10 correctly (1:02 vs 1:2), as well as finding batteries with other names, and printing the CPU speed (nice if you have speed stepping turned on). It rounds to the nearest 100MHz, which is easy to remove if you don't like it.
#!/bin/bash
speed=`grep "cpu MHz" /proc/cpuinfo | tr -d A-z | tr -d " " | tr -d :`
current=`grep remaining /proc/acpi/battery/*/state | tr -d A-z | tr -d " " | tr -d :`
total=`grep "design capacity:" /proc/acpi/battery/*/info | tr -d A-z | tr -d " " | tr -d :`
rate=`grep "present rate:" /proc/acpi/battery/*/state | tr -d A-z | tr -d " " | tr -d :`
int_speed=`bc << EOF
($speed+50) / 100 * 100
EOF
`
percent=`bc << EOF
100.0 * $current / $total
EOF
`
if [ $rate -eq 0 ]; then
echo $int_speed'MHz, '$percent'%, charging'
else
hours=`bc << EOF
(1.0*$current) / (1.0*$rate)
EOF
`
minutes=`bc << EOF
60.0 * $current / $rate - $hours * 60
EOF
`
if [ $minutes -lt 10 ]; then
echo $int_speed'MHz, '$percent'%, '$hours':0'$minutes
else
echo $int_speed'MHz, '$percent'%, '$hours':'$minutes
fi
fi
You can also try the 'acpi' pkg, which does exactly the same thing .
Considering the acpi package is only dated a few days ago, I don't feel too bad about not knowing about it.
BTW, here's an update I did to my script. This one prints minutes less than 10 correctly (1:02 vs 1:2), as well as finding batteries with other names, and printing the CPU speed (nice if you have speed stepping turned on). It rounds to the nearest 100MHz, which is easy to remove if you don't like it.
#!/bin/bash
speed=`grep "cpu MHz" /proc/cpuinfo | tr -d A-z | tr -d " " | tr -d :`
current=`grep remaining /proc/acpi/battery/*/state | tr -d A-z | tr -d " " | tr -d :`
total=`grep "design capacity:" /proc/acpi/battery/*/info | tr -d A-z | tr -d " " | tr -d :`
rate=`grep "present rate:" /proc/acpi/battery/*/state | tr -d A-z | tr -d " " | tr -d :`
int_speed=`bc << EOF
($speed+50) / 100 * 100
EOF
`
percent=`bc << EOF
100.0 * $current / $total
EOF
`
if [ $rate -eq 0 ]; then
echo $int_speed'MHz, '$percent'%, charging'
else
hours=`bc << EOF
(1.0*$current) / (1.0*$rate)
EOF
`
minutes=`bc << EOF
60.0 * $current / $rate - $hours * 60
EOF
`
if [ $minutes -lt 10 ]; then
echo $int_speed'MHz, '$percent'%, '$hours':0'$minutes
else
echo $int_speed'MHz, '$percent'%, '$hours':'$minutes
fi
fi
i've tried using it and it just say line 18 and line 29:[ too many arguments...
Offline
You can also try the 'acpi' pkg
...and acpitool, both do that and much more.
You need to install an RTFM interface.
Offline
Yes but to give the OP credit, they did write their script six and a half years ago.
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
You mean the script that doesn't work for Samuele (when ACPI interface stayed the same)? Okay, props to the author
Last edited by anrxc (2010-03-03 01:26:30)
You need to install an RTFM interface.
Offline
Haha OP is way old.. why resurrect this zombie?
Offline
i've tried using it and it just say line 18 and line 29:[ too many arguments...
Haha 7 year resurrection
Offline