Olaf Bohlen
2022-03-04 0a148dbe1f1c740eef4d8c59963d76d5a7da8501
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/ksh
 
UDI="/org/freedesktop/Hal/devices/pseudo/acpi_drv_0_battery0_0"
 
halout=$(/usr/sbin/lshal -l -u ${UDI})
 
perc=$(printf "${halout}" | nawk '$1~/battery.charge_level.percentage/ { print $3 }')
if [ x$(printf "${halout}" | nawk '$1~/battery.rechargeable.is_charging/ { print $3 }') == xtrue ]; then
  string="battery is charging"
  cstring="charge time"
elif [ x$(printf "${halout}" | nawk '$1~/battery.rechargeable.is_discharging/ { print $3 }') == xtrue ]; then
  string="battery is discharging"
  cstring="run time"
else
  string="battery is charged and runs on external power"
  cstring="run time"
fi
runtime=$(( $(printf "${halout}" | nawk '$1~/battery.remaining_time/ { print $3 }') / 60 ))
 
printf "I: the %s at %s%%, expected %s is %i min.\n" "$string" $perc "$cstring" $runtime