On Sat, 16 May 2015 12:50:19 -0400 (EDT), Gerald Pfeifer wrote:
On Thu 2015-05-07, Jean Delvare wrote:
So anyway Gerald's script can be simplified
Super! Thanks a lot, Jean (and Stefan). I've been travelling
the last two weeks, hence did not respond earlier.
You're welcome, no problem.
Below you'll find the script as I am using it
now, which works
both off /sys/class/power_supply and /proc/acpi/battery, so
across different versions of openSUSE and SUSE Linux Enterprise.
(Somehow the "if ls /sys/class/power_supply/BAT* >/dev/null; then"
strikes me as overkill. Is there a way to accomplish this easier?
Or can we assume the first battery always has index 0 and simply
check for BAT0?)
That would rather be a question for Thomas, but I'm afraid it's not
even guaranteed that batteries show up as BAT*, even though I think all
laptops I've seen so far used that name. But the first battery may not
be BAT0, for example on my old Panasonic Toughbook CF-18 it's named
BATA. To be on the bulletproof side I think you must check that
sysfs attribute "type" has value "Battery".
You can avoid the call to "ls", with a construct like:
if [ -n "$(shopt -s nullglob ; echo /sys/class/power_supply/BAT*)" ]
Not sure if it's significantly faster though. It might be easier to
just check for -d /sys/class/power_supply anyway, as I would guess that
in practice it's always populated when present?
====== script ======
while read l; do
i=`echo $l | cut -d' ' -f1`
printf "%5s " "$i"
printf " = %5s\n" "$s"
if ls /sys/class/power_supply/BAT* >/dev/null; then
for v in "energy_full_design" "energy_full" "energy_now"
printf "%18s = " "$v"
#cat /sys/class/power_supply/BAT*/$v | sed -e
's/\(.*\)\([0-9][0-9]\)0000$/\1.\2/' | sum
cat /sys/class/power_supply/BAT*/$v | sed -e 's/000$//' | sum
This assumes that the last 3 digits are always 000, which doesn't have
to be true. sed -e 's/...$//' would be safer.
for v in "design capacity" "last full capacity" "remaining
capacity" "rate"; do
printf "%18s = " "$v"
cat /proc/acpi/battery/BAT*/* | grep "$v:" | cut -d: -f2 | sum
SUSE L3 Support
To unsubscribe, e-mail: opensuse-kernel+unsubscribe(a)opensuse.org
To contact the owner, e-mail: opensuse-kernel+owner(a)opensuse.org