How to check if power cable is connected from the command line?

I'm running ubuntu on my notebook and I need a way to check (from the command line) if the power cable is connected. Is there any system file that keeps log of this? or is there a bash command that will help me?

I need this for a script that will behave differently depending on whether the power cord is plugged in or not.


$ cat /proc/acpi/ac_adapter/ACAD/state
state:                   on-line

or somthing similar depending on your architecture. There are many exports of machine state hiding in the /proc psuedo-directory.


$ cat /sys/class/power_supply/ADP1/online 
1
 [pull power]
$ cat /sys/class/power_supply/ADP1/online 
0

The value to put in place of ADP1 may vary.


I use something similar to:

acpi -a | grep AC | cut -d: -f2

in order to display the battery status on the wmii status bar.