Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 6 down vote accepted
$ 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.

share|improve this answer
    
Works exactly like that. Only it was /proc/acpi/ac_adapter/AC/state in my case. – Malabarba Jun 10 '10 at 1:51
$ 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.

share|improve this answer
    
Works exactly like that as well, only with "/sys/class/power_supply/AC/online" for me. I marked the other answer as accepted 'cause it was first, but both worked equally well. – Malabarba Jun 10 '10 at 1:53

I use something similar to:

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

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

share|improve this answer
    
This one didn't work with me because the acpi command wasn't installed. I didn't install it because the other methods were more practical, but it probably works fine as well. – Malabarba Jun 10 '10 at 1:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .