acpiexec - Run programs if on battery and/or ac power

Drew Broadley drew at corrupt.co.nz
Thu Jul 1 13:56:32 PDT 2004


I had a problem, whenever I was on battery I had cronjobs that were 
running every 5 minutes for various things (my ifconfigd script, which 
is like "whereami" for FreeBSD) and it sucked my battery down 3 times+ 
faster.

So here is the solution, I have made a Perl script ( and additional Perl 
Module BSD::Sysctl for other uses including this script) where you exec 
your current commands passed as an argument or option to acpiexec. By 
default, acpiexec will run the command when on AC power but NOT on battery.

Example of default usage:

    */60 * * * * /usr/sbin/acpiexec /home/drew/bin/xplanet_update 2> 
/dev/null

Example of custom switches (run on battery AND ac power):

    */60 * * * * /usr/sbin/acpiexec --batt=y /home/drew/bin/ifconfig_update

Example of displaying your laptops current power status:

    $ /usr/sbin/acpiexec status
   
    acpiexec status
    Default Settings:

        Run Command if on Battery: no
        Run Command if on AC Power: yes
 
    Current Machine Status:

        System is on Battery: no
        System is on AC Power: yes
 

I hope some people find this helpful, I have placed it on my cvs server:

    http://cvs.corrupt.co.nz/cgi-bin/cvsweb.cgi/acpiexec

    or via pserver

    $ cvs -d :pserver:anonymous at cvs.corrupt.co.nz:/public login
        <no password, just hit enter>
    $ cvs -d :pserver:anonymous at cvs.corrupt.co.nz:/public co acpiexec

   
You will need my BSD::Sysctl module located here:

    http://cvs.corrupt.co.nz/cgi-bin/cvsweb.cgi/.pm/modules/BSD/Sysctl.pm






More information about the freebsd-mobile mailing list