Monday, July 14, 2008

Are We Running on AC Power ???

I once mentioned that I use the script on_ac_power from the powermgmt_base package to determine whether my laptop is running on AC power.

Well, following a kernel upgrade to version 2.6.25, that script stopped working (see bug #473629). Here's a (debian-specific-works-on-my-machine) replacement script, based on the output of acpi:


#! /bin/bash
# this is a drop-in replacement for /usr/bin/on_ac_power
check_ac_power()
{
local ret=255
if [ -x /usr/bin/acpi ]; then
status=$(/usr/bin/acpi -aB | cut -d' ' -f 6)
case "$status" in
on-line)
ret=0
;;
off-line)
ret=1
;;
*)
;;
esac
fi
return $ret
}

check_ac_power

Note that I'm assuming that the system has a single AC power supply.

No comments:

Post a Comment