Battery vs. AC for a shell script?


Results 1 to 4 of 4

Thread: Battery vs. AC for a shell script?

  1. #1
    Join Date
    Sep 2002
    Location
    Valencia, California
    Posts
    436

    Battery vs. AC for a shell script?

    I'd like to write a shell script to do stuff only if I'm on AC and not running just on battery power. I checked dcop, I thought there might be something in klaptop, but there was nothing. I thought there might be something I could use in /proc but I got lost really quickly. Searches were all too general.

    Has anyone ever written a shell script that has to do with this?

    If anyone's wondering, I want to make a cronjob to start setiathome every night, but only if I'm plugged into the wall. I don't need to kill my battery looking for aliens

  2. #2
    Join Date
    Mar 2003
    Location
    Here
    Posts
    343
    Use perl or grep to parse the output of 'apm'.

    Eg. it usually outputs something like:
    Code:
    AC on-line, battery status high: 99% (3:27)
    So, a simple:
    Code:
    if [ `/usr/bin/apm | grep -c "AC\ on-line"` -eq "1" ]; then
        search_for_little_green_men &
    fi
    ... should do the trick.
    Last edited by terribleRobbo; 03-23-2004 at 07:02 AM.
    "Heisenberg may have been here."

  3. #3
    Join Date
    Aug 2001
    Location
    Somewhere, Texas
    Posts
    9,628
    With the 2.4 and 2.6 kernels it is /proc/acpi/ac_adapter/AC/state and the two states it is in is
    Code:
    state:                       on-line
    state:                       off-line
    in the cron job you can cat and grep the status and use that to determine to run SETI or not

    cat /proc/acpi/ac_adapter/AC/state | cut -c26-32

    For me that will show the state of on-line or off-line (test with yours to verify)

    I'll let you figure out the if/then statement to use

  4. #4
    Join Date
    Sep 2002
    Location
    Valencia, California
    Posts
    436

    Smile

    Absolutely perfect! Thanks guys!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •