On Thu 2015-05-07, Jean Delvare wrote:
So anyway Gerald's script can be simplified again to:
Super! Thanks a lot, Jean (and Stefan). I've been travelling the last two weeks, hence did not respond earlier. 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?) Gerald ====== script ====== #!/bin/bash sum() { s=0; while read l; do i=`echo $l | cut -d' ' -f1` printf "%5s " "$i" s=$(($s+$i)) done printf " = %5s\n" "$s" } if ls /sys/class/power_supply/BAT* >/dev/null; then for v in "energy_full_design" "energy_full" "energy_now" "power_now"; do 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 done else 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 done fi -- To unsubscribe, e-mail: opensuse-kernel+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-kernel+owner@opensuse.org