# [SCRIPT]s to handle ACPI events (incl. laptop-mode)

## friday

scripts to handle ACPI events

Here are is my config for an HP Compaq nx9000 Laptop.

It is inspired by https://forums.gentoo.org/viewtopic.php?t=63362

Thank you guys for all your great postings!

Features:

 needs only one file in /etc/acpi/events

 everthing else is done through /etc/acpi/action.sh

 handles battery low, ac in/out, powerbutton, lid close, laptop-mode

 /etc/acpi/on_boot.sh checks for an AC adapter at boot and takes action depending on that. It should be called through /etc/conf.d/local.start

What you need:

 Laptop with ACPI

 Kernel with ACPI + laptop-mode

 X must accept connections from localhost (xhost +localhost)

 for speedstepping the cpu I recommend powernowd, which can be found at http://www.deater.net/john/powernowd.html

 maybe some time to tweak it to your needs and post your experience  :Wink: 

TODO:

 integrate your improvements  :Smile: 

Latest versions available from http://cknoerle.homelinux.org/nx9000/stuff/acpi/

Also check my page about Gentoo on the HP Compaq nx9000 Laptop: http://cknoerle.homelinux.org/nx9000/

/etc/acpi/events/all_events

```

# This file matches all acpi events so there is no need for more

# event files in /etc/acpi/events/

# It calls /etc/acpi/action.sh with the whole event as arguments.

# The event is matched through an regular expression.

event=.*

action=/etc/acpi/action.sh %e

```

/etc/acpi/action.sh

```

#!/bin/bash

#

# /etc/acpi/action.sh (2004.01.17)

# called by acpid for all events

# Christopher Knoerle <cknoerle@gmx.net>

#

# This works with gentoo-sources, ac-sources, mm-sources on my

# HP Compaq nx9000 Laptop. For more information have a look at

# http://cknoerle.homelinux.org/nx9000/

# The latest version is available from

# http://cknoerle.homelinux.org/nx9000/stuff/acpi/

# This should be placed in /etc/acpi/action.sh and should be called by acpid.

# To make this happen you need the acpid installed and running.

# acpid can be obtained from http://acpid.sourceforge.net

# For this to work you need only one event handler in /etc/acpi/event

# It should contain something like the following:

#

# event=.*

# action=/etc/acpi/action.sh %e

# For speedstepping the cpu I use powernowd, which can be obtained from

# http://www.deater.net/john/powernowd.html

# I have written a very basic initscript for Gentoo, which you can find at

# http://cknoerle.homelinux.org/nx9000/stuff/

#

# For even better saving of battery power use a kernel with laptop-mode

# (see http://kerneltrap.org/node/view/653) and the laptop-mode shell-script

# which you can find at http://cknoerle.homelinux.org/nx9000/stuff/

# let's set some paths

LOGGER="/usr/bin/logger -t ACPID" # logs to syslog - an echo logs to /var/log/acpid

XGAMMA="/usr/X11R6/bin/xgamma"

XSET="/usr/X11R6/bin/xset"

LAPTOPMODE="/sbin/laptop-mode"

HDPARM="/sbin/hdparm"

#CPU_LIMIT="/proc/acpi/processor/CPU0/limit" # not needed with powernowd

BAT_STATE="/proc/acpi/battery/BAT1/state"

BAT_INFO="/proc/acpi/battery/BAT1/info"

AC_STATE="/proc/acpi/ac_adapter/ACAD/state"

LID_STATE="/proc/acpi/button/lid/LID/state"

# if we didn't know about an event

# log to /var/log/acpid to do something like 'grep #### /var/log/acpid' :-)

no_action ()

{

   echo "#### NO ACTION FOR EVENT: " $*

   exit 1

}

# AC Adapter plugged in

acad_in ()

{

   $LOGGER "AC Adapter plugged IN"

   if ps -A | grep -q X

   then

      $XGAMMA -d 0:0 -gamma 1.0 # set gamma in X to 100%

      $XSET -d 0:0 dpms 0 0 600 # shutdown display after 600s

   fi

   $LAPTOPMODE stop # stop laptop-mode

   $HDPARM -S 240 /dev/hda > /dev/null 2>&1 # spindown after 20min

   $HDPARM -B 255 /dev/hda > /dev/null 2>&1 # disable drive's APM

   # not needed with kernel 2.6.x - use powernowd

   #echo -n 0:0 > $CPU_LIMIT # set cpu performance state 0, throttling to 0

}

# AC Adapter plugged out

acad_out ()

{

   $LOGGER "AC Adapter plugged OUT"

   if ps -A | grep -q X

   then

      $XGAMMA -d 0:0 -gamma 0.7 # set gamma in X to 70%

      $XSET -d 0:0 dpms 0 0 120 # shutdown display after 120s

   fi

   $LAPTOPMODE start # start laptop-mode

   $HDPARM -S 4 /dev/hda > /dev/null 2>&1 # spindown after 20s

   $HDPARM -B 1 /dev/hda > /dev/null 2>&1 # enable drives's APM

   # not needed with kernel 2.6.x - use powernowd

   #echo -n 1:0 > $CPU_LIMIT # set cpu performance state 1, throttling to 0

}

# state of battery changed

# shutdown if battery capacity is low

battery ()

{

   if grep -q discharging $BAT_STATE

   then

      BAT_REMAIN=`awk '/remaining/ { print $3 }' $BAT_STATE`

      if (($BAT_REMAIN < `awk '/warning/ { print $4 }' $BAT_INFO`))

      then

         $LOGGER "battery capacity is critically low"

         btn_pwr

      fi

   fi

}

# powerbutton pressed

# if kde is running try to show dialog - else shutdown immediately

btn_pwr ()

{

   $LOGGER "Powerbutton pressed"

   if test -f $KDEDIR/bin/dcop && $KDEDIR/bin/dcop kdesktop > /dev/null 2>&1

   then

      $LOGGER "KDE running: asking user what to do"

      dcop --all-sessions ksmserver ksmserver logout 1 2 0 && exit 0

   else

      $LOGGER "shutdown initiated"

      /sbin/init 0

   fi

}

# lid closed/opened

# Anything useful to do when lid is closed/opened?

btn_lid ()

{

   if grep -q open $LID_STATE

   then

      $LOGGER "Lid opened"

   else

      $LOGGER "Lid closed"

   fi

}

# let's see which event occured and what action to take :-)

# have a look at /var/log/acpid to see what your events look like

# and adjust accordingly

case "$*" in

   ac_adapter\ ACAD\ 00000080\ 00000000)

      acad_out

   ;;

   ac_adapter\ ACAD\ 00000080\ 00000001)

      acad_in

   ;;

   battery\ BAT1\ 00000080\ 00000001)

      battery

   ;;

   button?lid\ LID\ 00000080\ ????????)

   # the last eight digits count the times the lid was shut

      btn_lid

   ;;

   button?power\ PWRF\ 00000080\ ????????)

   # the last eight digits count the times the button was pressed

      btn_pwr

   ;;

   *)

      no_action

   ;;

esac

# EOF

```

/etc/acpi/on_boot.sh

```

#!/bin/bash

#

# /etc/acpi/on_boot.sh (2004.01.17)

# called on boot to check for AC Adapter

# Christopher Knoerle <cknoerle@gmx.net>

#

# This works with gentoo-sources, ac-sources, mm-sources on my

# HP Compaq nx9000 Laptop. For more information have a look at

# http://cknoerle.homelinux.org/nx9000/

# The latest version is available from

# http://cknoerle.homelinux.org/nx9000/stuff/acpi/

# This should be placed in /etc/acpi/on_boot.sh and should be called

# through /etc/conf.d/local.start

# You can achieve this by doing the following:

# echo "/etc/acpi/on_boot.sh" >> /etc/conf.d/local.start

# lets set some paths

LOGGER="/usr/bin/logger -t ACPID" # logs to syslog - an echo logs to /var/log/acpid

XGAMMA="/usr/X11R6/bin/xgamma"

XSET="/usr/X11R6/bin/xset"

LAPTOPMODE="/sbin/laptopmode"

HDPARM="/sbin/hdparm"

#test for ac

if grep -q 'off-line' /proc/acpi/ac_adapter/ACAD/state

then

   $LOGGER "AC Adapter plugged OUT"

   if ps -A | grep -q X

   then

      $XGAMMA -d 0:0 -gamma 0.7 # set gamma in X to 70%

      $XSET -d 0:0 dpms 0 0 120 # shutdown display after 120s

   fi

   $LAPTOPMODE start # start laptop-mode

   $HDPARM -S 4 /dev/hda > /dev/null 2>&1 # spindown after 20s

   $HDPARM -B 1 /dev/hda > /dev/null 2>&1 # enable drives's APM

   # not needed anymore - use powernowd

   #echo -n 1:0 > /proc/acpi/processor/CPU0/limit # set cpu performance state 1, throttling to 0

else

   exit 0

fi

# EOF

```

Last edited by friday on Sat Jan 31, 2004 10:43 pm; edited 21 times in total

----------

## puddpunk

hey man! Thats great! I've been looking for a set of scripts like that for my laptop  :Very Happy: 

Thanks heaps for sharing that mate.

Cheers,

Chris.

----------

## friday

Please post any changes needed for your laptop and/or additions you made  :Smile: 

Also don't forget your laptop model.

Happy powersaving  :Wink: 

----------

## artooman

Does anyone have any idea how to shut off the notebook screen?  I would be great to update this script to shutoff the screen when the lid closes.

----------

## friday

What exactly do you mean?

When I close the lid on my nx9000 the display is turned off.

Maybe the xset manpage can help you:

 *Quote:*   

> 
> 
> dpms flags... 
> 
> The dpms option allows the DPMS (Energy Star) parameters to be set. The option can take up to three numerical values, or the `force' flag followed by a DPMS state. The `force' flags forces the server to immediately switch to the DPMS state specified. The DPMS state can be one of `standby', `suspend', `off', or `on'. When numerical values are given, they set the inactivity period (in units of seconds) before the three modes are activated. The first value given is for the `standby' mode, the second is for the `suspend' mode, and the third is for the `off' mode. Setting these values implicitly enables the DPMS features. A value of zero disables a particular mode.
> ...

 

Any ideas what else to do when the lid is closed?

----------

## jocsch

Depends on your graphic chip. I have a radeon and there is this nice tool called radeontool. Already in portage.

Do a

```

radeontool light off

```

to switch the display off.

----------

## aman

But you are not turning off the display, you are just turning off the backlight.  If you look very closely in low light, you will still be able to make out your desktop.  So does anybody know how to really kill the display and really save some power?

----------

## hulk2nd

@friday

how did you know the syntax from the acpi events? cause i have now three different scripts and in every one the syntax of the event is different. with the latest version of acpid the scripts dont work anymore so i would like to know how i can come to the syntax to get them working again.

thanks in advance and greets,

hulk

----------

## friday

acpid logs the received events to /var/log/acpid (on my machine).

Take a look at the acpid manpage  :Wink: 

HTH

----------

## Bash[DevNull]

My ACPI support not full, and i have not LID-STATUS... but by event and values that transmit acpid we can determinate OPEN/CLOSE status...

```
VALUE2=$4

btn_lid ()

{

   if [ -e $LID_STATE ] ; then

      if grep -q open $LID_STATE >/dev/null 2>&1

      then

       #OPEN

       ....

        fi

      else

      #CLOSE

       ....

      fi

   else

      if (( $(($VALUE2 % 2)) == 1))

      then

        #Close

         ....

      else

        #OPEN

         ....

      fi

   fi

}
```

And some add-ons for battery!

It is will be notice all time from alarm mWh to low mWh (fro acpi-proc)

```
BAT_STATE="/proc/acpi/battery/BAT0/state"

BAT_INFO="/proc/acpi/battery/BAT0/info"

BAT_ALARM="/proc/acpi/battery/BAT0/alarm"

BAT_ALR=`awk '{ print $2}' $BAT_ALARM 2>/dev/null || echo "300"`

BAT_LOW=`awk '/low/ { print $4 }' $BAT_INFO 2>/dev/null || echo "150"`

{

   if grep -q discharging $BAT_STATE >/dev/null 2>&1

   then

      if ((`awk '/remaining/ { print $3 }' $BAT_STATE` < $BAT_LOW))

      then

         $LOGGER "[acpid] battery capacity is critical low."

      else

         $LOGGER "[acpid] battery capacity less than $BAT_ALR mWh"

         BAT_ALR=$(($BAT_ALR - 50))

         echo $BAT_ALR > $BAT_ALARM

         $MPL "/etc/acpi/sounds/Diving In.mp3" 2>/dev/null

      fi

   fi

}
```

----------

## Bash[DevNull]

I modifer a little previous script and now:

1) If LID closed monitor is off

2) When bat. less than alarm mWh LapTop starting to beeping !  :Wink: 

```
VALUE2=$4

# if lid closed force monitor off

btn_lid ()

{

   if grep -v -q open $LID_STATE >/dev/null 2>&1 || (( $(($VALUE2 % 2)) == 1))

   then

        $LOGGER "[acpid] lid is closed"

        if ps -A | grep -q X ; then

          $XSET dpms force off

        fi

   else

        $LOGGER "[acpid] lid is opened"

        if ps -A | grep -q X ; then

          $XSET dpms force on

        fi

   fi

}

LOGGER="/usr/bin/logger"

XSET="/usr/X11R6/bin/xset -display :0.0"

BEEP="/usr/bin/beep"

BAT_STATE="/proc/acpi/battery/BAT0/state"

LID_STATE="/proc/acpi/button/lid/LID/state"

BAT_INFO="/proc/acpi/battery/BAT0/info"

BAT_ALARM="/proc/acpi/battery/BAT0/alarm"

BAT_ALR=`awk '{ print $2}' $BAT_ALARM 2>/dev/null || echo "300"`

BAT_LOW=`awk '/low/ { print $4 }' $BAT_INFO 2>/dev/null || echo "150"`

battery ()

{

   if grep -q discharging $BAT_STATE >/dev/null 2>&1

   then

      if ((`awk '/remaining/ { print $3 }' $BAT_STATE` < $BAT_LOW))

      then

         $LOGGER "[acpid] battery capacity is critical low."

         btn_pwr

      else

         $LOGGER "[acpid] battery capacity less than $BAT_ALR mWh"

         echo $BAT_LOW > $BAT_ALARM

         # start beep'ing with delay 5 sec

         $BEEP -f 1500 -r 100 -d 5000 &

      fi

   fi

}
```

----------

## hulk2nd

thanks @friday ... should haved used my eyes ...

i have another question:

if you look at this string for example:

```
$XSET -d 0:0 dpms 0 0 120
```

is it possible to say the radeontool to turn off the backlight after 120s except xset, cause xset doesnt work here. in other words: how can i implement a delay into the command "radeontool light off"?

EDIT

ok, i've found a solution  :Very Happy: 

there is a perl script that recognizes a running xscreensaver and then activates the radeontool. if somebody is interested (it's not my one, just found it on the web!) ...

```
#!/usr/bin/perl -w

use strict;

#

#  This handy script watches when the screensaver activates and

#  toggles the LCD backlight.  You won't see more than a 

#  second of the screensaver, so you might as well chose one

#  which consumes few MIPS/battery.

#

#  You will probably want to make this script owned by root

#  and SUID.  Also you will need the perl-suidperl package installed

#  for RedHat systems.

#     chown root lightwatch

#     chmod u+x lightwatch

#

$ENV{'PATH'} = '/bin:/usr/bin';

delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

$<=0;  # become root not just effective root

open(XS,"/usr/bin/xscreensaver-command -watch|") or die;

while(<XS>) {

   if(/^BLANK/i) {

      system("/usr/bin/radeontool light off");

   } elsif(/^UNBLANK/i) {

      system("/usr/bin/radeontool light on");

   }

}
```

EDIT

greets,

hulk

----------

## captnjameskirk

I've modified the lightwatch script somewhat to suit my needs. I wanted some screensaver activity before the light was turned off. Also, I removed the need for perl-suidperl (but added the need for sudo). After the screensaver has cycled the specified number of times, xcreensaver-command -throttle is used to turn off any screensaver activity at all so no cpu cycles are used, and the light is turned off.

```
#!/usr/bin/perl -w

# This script has been adapted to allow using sudo to

# execute radeontool, and to turn the light off after

# a specified number of screensaver cycles.

# If radeontool is in /usr/bin add /usr/bin/radeontool 

# to the sudoers file so that no password is needed

# to execute the command by the user who is running

# this script. Make sure that xscreensaver is set

# to cycle between savers every couple of minutes,

# for example 2, then set $max to 10 to have the

# light turned off after 20 minutes. Then place this

# script in your .xinitrc file so that it is run after

# xscreensaver is started.

$c=0;       # screensaver counter

$max=10;   # max cycles before turning light off

open(XS,"xscreensaver-command -watch|") or die;

while(<XS>) {

   if(/^RUN/i) {

      $c++;

      # after $max changes of the screensaver, turn the light off

      if($c>=$max)  {

     system("sudo /usr/bin/radeontool light off");

     # turn off running display modes to save cpu cycles

     system("xscreensaver-command -throttle > /dev/null");

      }

   } elsif(/^UNBLANK/i) {

      if($c>=$max) {

     $c=0;   # reset the counter

           system("sudo /usr/bin/radeontool light on");

     system("xscreensaver-command -unthrottle > /dev/null");

   }

   }

}

```

Oops, edited to correct a typo.   :Embarassed: 

----------

## crisscross

I am having a problem tracking ACPI events to see what events are used on my Inspiron 1100 I appoligize for my lack of knowledge on this topic however this is my first time to run linux on my laptop.

I tried to run acpi in debug mode here are my results

```
[Thu Nov  6 23:59:33 2003] BEGIN HANDLER MESSAGES

/bin/sh: -c: line 1: syntax error near unexpected token `;;'

/bin/sh: -c: line 1: `/etc/acpi/default.sh              ;;'

[Thu Nov  6 23:59:33 2003] END HANDLER MESSAGES

[Thu Nov  6 23:59:33 2003] action exited with status 2

[Thu Nov  6 23:59:33 2003] DBG: 1 total rule matched

[Thu Nov  6 23:59:33 2003] completed event "            ;;"

[Thu Nov  6 23:59:33 2003] received event "esac"

[Thu Nov  6 23:59:33 2003] DBG: rule from /etc/acpi/events/default matched

[Thu Nov  6 23:59:33 2003] executing action "/etc/acpi/default.sh esac"

[Thu Nov  6 23:59:33 2003] BEGIN HANDLER MESSAGES

[Thu Nov  6 23:59:33 2003] END HANDLER MESSAGES

[Thu Nov  6 23:59:33 2003] action exited with status 0

[Thu Nov  6 23:59:33 2003] DBG: 1 total rule matched

[Thu Nov  6 23:59:33 2003] completed event "esac"
```

what is it that i am looking for here?

The 3 things that I am looking for is the

a lid close event so that I can call the xset dpms force off

a power button press so that I can call the xset dpms force standby

and the 2nd button on the laptop which in xp would exicute a browser.

Any help would be great . Thanks alot.

----------

## friday

```

completed event "            ;;"

received event "esac"

completed event "esac"

```

Looks messed up somehow...

On mx HP/Compaq nx9000 an event-log look like this:

```

received event "button/lid LID 00000080 00000001"

...

completed event "button/lid LID 00000080 00000001"

received event "button/power PWRF 00000080 00000001"

...

completed event "button/power PWRF 00000080 00000001"

```

The "button/power PWRF 00000080 00000001" strings is what to match with the rules.

Maybe there is a solution on http://acpi.sourceforge.net/

----------

## crisscross

What commands did you use to trap your events?

----------

## friday

Well as mentioned before the acpid logs to /var/log/acpid by default.

There you can look up what a certain event looks like.

Then you can modify my action.sh script to match your events and place all the files in the mentioned directories.

HTH

----------

## crisscross

My log file just reads.

```
[Thu Nov  6 21:15:05 2003] starting up

[Thu Nov  6 21:15:05 2003] 1 rule loaded

[Thu Nov  6 21:28:05 2003] exiting

[Thu Nov  6 21:37:11 2003] starting up

[Thu Nov  6 21:37:11 2003] 1 rule loaded

[Thu Nov  6 21:38:15 2003] exiting

[Thu Nov  6 21:38:16 2003] starting up

[Thu Nov  6 21:38:16 2003] 1 rule loaded
```

If I run this command:

acpid -d -e /etc/acpi/events/default

I get these results.

```
[Sat Nov  8 09:50:21 2003] starting up

[Sat Nov  8 09:50:21 2003] DBG: parsing conf file /etc/acpi/events/default

[Sat Nov  8 09:50:21 2003] 1 rule loaded

[Sat Nov  8 09:50:21 2003] received event " This is the ACPID default configuration, it takes all"

[Sat Nov  8 09:50:21 2003] DBG: rule from /etc/acpi/events/default matched

[Sat Nov  8 09:50:21 2003] executing action "/etc/acpi/default.sh  This is the ACPID default configuration, it takes all"

[Sat Nov  8 09:50:21 2003] BEGIN HANDLER MESSAGES

/bin/sh: line 1: /etc/acpi/default.sh: Permission denied

[Sat Nov  8 09:50:22 2003] END HANDLER MESSAGES

```

----------

## friday

acpid -d turns on debug mode. That's ok.

acpid -e /etc/acpi/events/default is nonsense.

This is definitely _not_ the file your kernel writes the acpi events to. This should be /proc/acpi/events which is read by acpid by default. So you don't have to give the -e option unless your kernel's acpi-events-interface is not /proc/acpi/events.

All of this is explained in the manpage, of course.

So what you have to do is start the acpid by typing '/etc/init.d/acpid start'. After that the acpid "listens" for events through the file /proc/acpi/events and logs these and the taken actions to /var/log/acpid.

Try the following:

'tail -f /var/log/acpid' and then close the lid of your notebook or plug the AC-adapter in/out. You will see  :Smile: 

The directory /etc/acpi/events/ contains files whith rules.

These are read by acpid on startup to know, what to do when a certain event is received. With my setup you can safely delete the default in there and copy my all_events and name it whatever you want.

It tells acpid what to do when an event matched by the file is received.

In my setup it would always execute /etc/acpi/action.sh and pass the whole event to it.

action.sh then tries to match the event and execute some stuff depending on that.

I'd suggest having a look at the acpid manpage and http://www.tldp.org/LDP/abs/html/

HTH

----------

## crisscross

This is my exact problem.

tail -f /var/log/acpid

```
[Thu Nov  6 23:51:02 2003] 1 rule loaded

[Fri Nov  7 00:06:26 2003] exiting

[Fri Nov  7 20:54:49 2003] starting up

[Fri Nov  7 20:54:49 2003] 1 rule loaded

[Fri Nov  7 20:57:57 2003] exiting

[Fri Nov  7 21:38:12 2003] starting up

[Fri Nov  7 21:38:12 2003] 1 rule loaded

[Fri Nov  7 21:45:14 2003] exiting

[Sat Nov  8 10:37:50 2003] starting up

[Sat Nov  8 10:37:50 2003] 1 rule loaded
```

i can tail it all I want i do not see the events.

I am sure that if I could find out what the actual event names where when I do somethign like close the lid or press the power button I could do the rest. I have tried yur scripts as well no diffrence. I have acpi complied into the kernel I have the kde's batery monitor working just need a couple more things.

Bottom line I cant find the event for the lid. their has to be one becasue it worked on xp.

----------

## friday

Have a look at 'dmesg | grep ACPI'.

Maybe it tells you that your Hardware is not supported or sth. similar.

Try to find solutions with google. Search for your laptop model and linux and acpi.

HTH

----------

## crisscross

OK I'll do some checking thanks for your help.

----------

## ed0n

thanks.

----------

## gcasillo

A hearty thanks for your contribution, Friday. I'm going to give PowerNowd a looksy now to see if I can temper my laptop's tendency to run too hot when compiling large programs. It has shutdown from the heat several times already, and I just had to replace its hard drive this week.   :Crying or Very sad: 

----------

## bdraw

I have worked on this for a few days. No luck

I am very new to bash scirpting.

I want my laptop screen to turn off and the xscreensaver to throttle when I close the lid. I would also like the oposite to happen when I open it.

So I edited my script.

```

XSCREENSAVER="/usr/bin/xscreensaver-command"

# lid closed 

# When the lid closes throttle xscreensaver when it opens unthrottle it. 

btn_lid ()

{

   if grep -q open $LID_STATE

   then

      $LOGGER "[acpid] Lid opened"

      $XSCREENSAVER --unthrottle

   else

      $LOGGER "[acpid] Lid closed"

      $XSET dpms force off

      $XSCREENSAVER --throttle

  fi

}

```

I did not change anything else in the script and my logs show

```

ACPI action lid is not defined

[acpid] Lid closed

ACPI action lid is not defined

```

What else do I need to do to make this work?

----------

## hulk2nd

check the patch at the beginning:

LID_STATE=/proc/acpi/button/lid/LID/state

for example in my case it is LID0 instead of LID.

greets,

hulk

----------

## bdraw

 *hulk2nd wrote:*   

> check the patch at the beginning:
> 
> LID_STATE=/proc/acpi/button/lid/LID/state
> 
> for example in my case it is LID0 instead of LID.
> ...

 

Thanks for the sugestion.

The path is set correctly, and I can tell the IF statment is true because the event gets loged. 

I switched to metalog and it seems there is more information that might help.

This is from /var/log/acpi

```

[Fri Dec 12 14:08:42 2003] received event "button/lid LID 00000080 00000003"

[Fri Dec 12 14:08:42 2003] executing action "/etc/acpi/default.sh button/lid LID 00000080 00000003"

[Fri Dec 12 14:08:42 2003] BEGIN HANDLER MESSAGES

[Fri Dec 12 14:08:42 2003] END HANDLER MESSAGES

[Fri Dec 12 14:08:42 2003] action exited with status 0

[Fri Dec 12 14:08:42 2003] executing action "/etc/acpi/action.sh button/lid LID 00000080 00000003"

[Fri Dec 12 14:08:42 2003] BEGIN HANDLER MESSAGES

#### NO ACTION FOR EVENT:

[Fri Dec 12 14:08:42 2003] END HANDLER MESSAGES

[Fri Dec 12 14:08:42 2003] action exited with status 1

[Fri Dec 12 14:08:42 2003] completed event "button/lid LID 00000080 00000003"

[Fri Dec 12 14:08:46 2003] received event "button/lid LID 00000080 00000004"

[Fri Dec 12 14:08:46 2003] executing action "/etc/acpi/default.sh button/lid LID 00000080 00000004"

[Fri Dec 12 14:08:46 2003] BEGIN HANDLER MESSAGES

[Fri Dec 12 14:08:46 2003] END HANDLER MESSAGES

[Fri Dec 12 14:08:46 2003] action exited with status 0

[Fri Dec 12 14:08:46 2003] executing action "/etc/acpi/action.sh button/lid LID 00000080 00000004"

[Fri Dec 12 14:08:46 2003] BEGIN HANDLER MESSAGES

#### NO ACTION FOR EVENT:

[Fri Dec 12 14:08:46 2003] END HANDLER MESSAGES

[Fri Dec 12 14:08:46 2003] action exited with status 1

[Fri Dec 12 14:08:46 2003] completed event "button/lid LID 00000080 00000004"

```

----------

## friday

bdraw, it seems you have messed up the script somehow.

Otherwise it wouldn't echo the "#### no action..." stuff to /var/log/acpi.

Have you changed the order within the case ... esac switch?

----------

## b0fh

I'd like to put my Thinkpad T23 into sleep-mode when lid is closed. This worked properly and without acpid in kernel version < 2.6.0-test10. But in 2.6.0 it only enters sleep-mode when I pass acpi=off at bootup... Very strange. Any ideas how to fix this?

----------

## Sibben

b0fh: 

Unfortunalty I don't have a solution but if you get it working don't forget to take the network down when the lid is closed and turn it on when you open the lid. Maybe it's not neccesary to do a ifconfig ethX down on a lid close but I guess it more correct then not doing so. 

And many thanks to everybody who has contributed to this thread, it's great!

----------

## Toshimitsu

Like your script, but I did some modifications to it myself.

I've got a Dell X300, and i've got the following ACPI events:

Lid closing: LID0 00000080 0000000x

Suspend (Fn+esc): SLPB 00000080 0000000x

AC plugged out: ADP1 00000080 00000000

AC plugged in: ADP1 00000080 00000001

So i had to do the corresponding changes to the action and on_boot script.

My laptop automatically dims the display when power is plugged out, and the display-light-buttons work without any programs running. So.. I didn't bother having the xgamma-commands in there.

The only problem I'm having now is that the powerbutton don't seem to be generating any events.. I've got the file /proc/acpi/button/power/PWRF/info .. but apparently something's not working 100% ..

Oh, and to tune the cpu-speed, i just use speedfreq -p performance/dynamic when the power's plugged in/out.

----------

## jana

Toshimitsu,

Thanks to some great help from jetblack in this forum, I've been working on getting ACPI functioning on my Dell x200.  I know the machines are different, but it sounds like you've got some features that we don't, perhaps working out of the box...  what kernel are you running?  Did you have to do any tweaking to get ACPI going?  (Unrelated:  do you have an internal wireless card?  I've got a friend who can't get his to work.)

As far as your power button problem...  I know that I don't have a PWRF/state file.  Do you, or are you trying to throw an event due to something in the info file?

thanks!

 - j

----------

## MiNeR

hello!

there are nice scripts in this post. 

thx @all!!! but i was not very happy with the radeontool light off / xscreensaver solution because if i was working on the console and the light turns off, i needed to switch to the x display to deactivate the screensaver and get the backlight on. so i wrote a little c program what does all the things for me. i waits for 20 minutes of idle and then turns off the backlight. if you move the mouse or press a key the light turns on again.

it is written for the 2.6 kernel.

hope you like it  :Very Happy: 

```

#include <stdio.h>

#include <time.h>

int main( int argc, char argv[] )

{

   int i, j;

   char ch, buffer[1024]="", kb[512]="", kb_old[512]="", ps2[512]="", ps2_old[512]="";

   char *colon, *found, *last;

   FILE *fd;

   time_t saved_time;

   enum bool { true = 1, false = 0 } off=false;

   saved_time = time(NULL);

   while (1) {

      for (j=0; j<2; j++) {

         fd = popen( "cat /proc/interrupts", "r" );

         if ( fd == NULL ) {

            exit(-1);

         }

         i=0;

         while ( (ch = fgetc(fd)) != EOF && i < 1024 ) {

            buffer[i] = ch;

            i++;

         }

         pclose(fd);

         i=0;

         colon = buffer;

         while (1) {

            found = strstr( colon, "i8042" );

            if ( found != NULL ) {

               while ( colon < found ) {

                  last = colon;

                  colon = strstr( colon+1, ":" );

               }

               if ( j != 0 ) {

                  if ( i == 0 )

                     memcpy( kb, last, found-last-1 );

                  else

                     memcpy( ps2, last, found-last-1 );

               } else {

                  if ( i == 0 )

                     memcpy( kb_old, last, found-last-1 );

                  else

                     memcpy( ps2_old, last, found-last-1 );

               }

               i++;

            } else {

               

               if ( j == 0 )

                  sleep(1);

               break;

            }

         }

      }

      if ( strcmp( kb, kb_old) == 0 && strcmp( ps2, ps2_old ) == 0 ) {

         

         fprintf( stderr, "no userinput\n" );

         if ( off == false && time(NULL) - saved_time >= 20*60 ) {

            system("sudo /usr/bin/radeontool light off");

            off=true;

         }

      } else {

         fprintf( stderr, "userinput\n" );

         saved_time = time(NULL);

         

         if ( off == true ) {

            system("sudo /usr/bin/radeontool light on");

            off=false;

         }

      }

      fprintf( stderr, "time: %ld\nsaved time: %ld\nsaved t. - t.: %ld\n", time(NULL), saved_time, time(NULL)-saved_time );

   }

}

```

----------

## angagon

I have an ACPI script that does a 

```
su $USER -c "/usr/X11R6/bin/xset dpms force off -display :0.0"
```

and obviously the on version as well.  But when I push the lid button /var/log/acpid complains

```
Xlib: connection to ":0.0" refused by server

Xlib: No protocol specified

/usr/X11R6/bin/xset:  unable to open display ":0.0"
```

I have set 

```
xhost +localhost
```

, but while that command doesn't complain it seems not to affect anything.  But if I do a 

```
xhost +
```

 the xset command works. 

Any ideas?

EDIT:

Oh, yeah, before I knew about xhost if I just restarted acpid upon starting X, xset worked.

----------

## friday

I just updated the scripts to suport laptop-mode capable kernels  :Smile: 

----------

## Bouncelot

I am trying out the scripts, thanks guys! so far so good.  :Smile: 

was wondering where/how I can get  "/sbin/laptop-mode" is this another script? I found and added the laptopmode patch to the kernel, but can find no refrences to a laptop-mode exicutable....

Thanks,

----------

## friday

Yes, /sbin/laptopmode is a script.

It was in the docs with mm-sources-2.6.1-mm4 I think.

----------

## Bouncelot

found it, thanks.

----------

## Bouncelot

There were some changes i had to make.

for the xset and xgamma I had to su to the current user. otherwise I got "/usr/X11R6/bin/xset:  unable to open display "0:0""

```

su $USER -c "$XGAMMA -d :0 -gamma 1.0" # set gamma in X to 100%

su $USER -c "$XSET -d :0 dpms 0 0 600" # shutdown display after 600s

```

I hardcoded $USER to my username, also "-d 0:0" wouldn't work but "-d :0" did...

I also changed acad in and out to do the hd, speedstep, and laptop mode things even if X was not running.

```

   $LOGGER "AC Adapter plugged IN"

   if ps -A | grep -q X

   then

      su $USER -c "$XGAMMA -d :0 -gamma 1.0" # set gamma in X to 100%

      su $USER -c "$XSET -d :0 dpms 0 0 600" # shutdown display after 600s

   fi

   $SPEEDFREQ -p performance

   $LAPTOPMODE stop # stop laptop-mode

   $HDPARM -S 240 /dev/hda > /dev/null 2>&1 # spindown after 20min

   $HDPARM -B 255 /dev/hda > /dev/null 2>&1 # disable drive's APM

```

finaly I had to remove the call to no_action, and insert it's contents directly into the case statment, $+ had no value once no_action was called.

```

*)

      #no_action

      echo "#### NO ACTION FOR EVENT: " $*

      exit 1

;;

```

I may be looking at battery status next week, if I work anything out I'll post it here.

----------

## jetblack

Thanks for all these scripts! I've been playing around with them now that I've got ACPI mostly working. I don't have any major changes to contribute yet, but I do have a question.

I'm using the hdparm settings suggested here, and I've noticed that something seems to be accessing my hard drive every 10-30 seconds, even if I'm not doing anything on the machine. Perhaps I should expect that, since I have to access /proc/acpi/battery/BAT1/info & /proc/acpi/battery/BAT1/state whenever there is a battery event. Of course, this causes the drive to spin back up momentarily. Does anyone else notice that? Will that significantly reduce my hard drive's lifespan down the road? Also, will the repeated spinups cancel out any power savings that I'm getting from using these hdparm settings?

Thanks again for the great thread!

----------

## friday

 *Bouncelot wrote:*   

> 
> 
> I also changed acad in and out to do the hd, speedstep, and laptop mode things even if X was not running.
> 
> 

 

That makes somewhat more sense. Thanks for pointing this out.

I made that changes when I was pretty tired  :Rolling Eyes: 

 *jetblack wrote:*   

> 
> 
> I'm using the hdparm settings suggested here, and I've noticed that something seems to be accessing my hard drive every 10-30 seconds, even if I'm not doing anything on the machine.
> 
> Perhaps I should expect that, since I have to access /proc/acpi/battery/BAT1/info & /proc/acpi/battery/BAT1/state whenever there is a battery event. Of course, this causes the drive to spin back up momentarily. Does anyone else notice that?
> ...

 

/proc is not a real filesystem but a virtual one. So I don't think there is any access to your hd when reading/writing proc.

Maybe you are low on mem and grep/awk/whatever is loaded from disk each time, but I don't think this happens under linux. These should be in mem and not swapped out since they're run quite often when using these scripts.

Does $LAPTOPMODE exist on your drive?

Is it actually the right script?

Do you have a kernel with laptop-mode?

 *jetblack wrote:*   

> 
> 
> Will that significantly reduce my hard drive's lifespan down the road? Also, will the repeated spinups cancel out any power savings that I'm getting from using these hdparm settings?
> 
> 

 

Recent HD's built into laptops are designed to be spun up/down a lot of times, so this won't be too significant. I think there was some discussion about that on the net...

Repeated spinups do of course effect the powerconsumption.

AFAIR someone reported an increase from 2h to 3h for his laptop running on battery. That's a 50% gain  :Shocked: 

----------

## jetblack

 *friday wrote:*   

> /proc is not a real filesystem but a virtual one. So I don't think there is any access to your hd when reading/writing proc.

 

*slaps head*

Oh yeah. I'm not sure what (or if) I was thinking there. I guess if the system is writing to anything, it's /var/log/acpid.log (or whatever that file is). That's a possibility.

 *friday wrote:*   

> Maybe you are low on mem and grep/awk/whatever is loaded from disk each time, but I don't think this happens under linux. These should be in mem and not swapped out since they're run quite often when using these scripts.

 

Possible - I'll check that out later today, but I should have plenty of memory.

 *friday wrote:*   

> Does $LAPTOPMODE exist on your drive?
> 
> Is it actually the right script?
> 
> Do you have a kernel with laptop-mode?

 

Oh, I'm not doing anything with laptop-mode yet. I was taking it a step at a time. If I can't track this down, I'll give laptop-mode a try and see if it helps.

 *friday wrote:*   

> Recent HD's built into laptops are designed to be spun up/down a lot of times, so this won't be too significant. I think there was some discussion about that on the net...
> 
> Repeated spinups do of course effect the powerconsumption.
> 
> AFAIR someone reported an increase from 2h to 3h for his laptop running on battery. That's a 50% gain 

 

Glad to hear about the spinups. That is an impressive gain. I'll have to do some benchmarking. I can say that it seemed to last longer yesterday, but that's not particularly quantitative.  :Smile: 

----------

## friday

 *jetblack wrote:*   

> 
> 
> Oh, I'm not doing anything with laptop-mode yet. I was taking it a step at a time. If I can't track this down, I'll give laptop-mode a try and see if it helps.
> 
> 

 

It really should solve this problem, see

ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.2-rc1/2.6.2-rc1-mm1/broken-out/laptop-mode-2.patch

I could not find a better source on the web, but the doc comes with the kernel sources. At least mm-sources  :Smile: 

----------

## jetblack

 *friday wrote:*   

>  *jetblack wrote:*   
> 
> Oh, I'm not doing anything with laptop-mode yet. I was taking it a step at a time. If I can't track this down, I'll give laptop-mode a try and see if it helps.
> 
>  
> ...

 

Thanks. It certainly helps. Looks like it's about every 30-60 seconds now. I'll keep playing with it, but at least there doesn't seem to be any reason not to use laptop-mode. And fortunately, it applies to the vanilla kernels, since I'm using a rather heavily patched 2.6.1 kernel, and some of the patches don't apply to mm-sources. I could probably fix them, but I'm feeling lazy right now.  :Wink: 

----------

## MyZelF

 *hulk2nd wrote:*   

> 
> 
> there is a perl script that recognizes a running xscreensaver and then activates the radeontool.

 

Here's another one, that doesn't require neither xscreensaver nor perl:

```
#!/bin/bash

################################################################

# dpmswatch.sh

# Copyright 2003 Rob Mahurin <rob@utk.edu>

# Available for use under the General Public License

# No warranty etc.

##

#  This is based on lightwatch.pl, but instead of using

#  xscreensaver-command -watch, it uses xset to query the DPMS state

#  of the LCD.  If the desired DPMS state is off, blank the LCD

#  backlight using radeontool.

##

#  If your system gives a different output to this command :

#  $ for i in standby suspend off on ; do

#      xset dpms force $i ;

#      xset q ;

#    done | grep Monitor | awk '{print $3 $4 }'

#    inStandby

#    inSuspend

#    Off

#    On

#  then you may have to modify this script.

##

#  It's written in shell instead of Perl because that's what I know.

################################################################

# commands to use.  Correct on Debian woody.

XSET=/usr/bin/X11/xset

RADEONTOOL=/usr/bin/radeontool

# The polling intervals, for feeding to sleep(1).  Is there way to

# make this event-driven, rather than poll all the time?  Does it

# matter?

#

# Notice that we don't want to watch the xscreensaver, since that

# would bring up the password box without turning on the LCD.  Very

# confusing.

inStandby_INTERVAL=5s

inSuspend_INTERVAL=5s

Off_INTERVAL=1s

On_INTERVAL=5s

INTERVAL=0s;

# check to make sure we have all the commands we need

for i in $XSET $RADEONTOOL

do    [ -x $i ] || { echo $i not found >&2 || exit 0 ; }

done

while : ; do

    # what is the state of the monitor?

    STATE=$($XSET q | grep Monitor | awk '{print $3 $4}')

    # if the monitor is in standby or suspend, change the polling

    # interval # but turn the light on or off.  If the monitor is Off,

    # turn off the # LCD backlight.  If the monitor is On, turn on the

    # backlight.  Then sleep until it's time to check again.

    case $STATE in

        inStandby)

                INTERVAL=$inStandby_INTERVAL

                ;;

        inSuspend)

                INTERVAL=$inSuspend_INTERVAL

                ;;

        Off)

                INTERVAL=$Off_INTERVAL

                $RADEONTOOL light off

                ;;

        On)

                INTERVAL=$On_INTERVAL

                $RADEONTOOL light on

                ;;

        # if something strange happens, turn the light on and fail.

        *)

                $RADEONTOOL light on

                exit 1

                ;;

    esac

    sleep $INTERVAL

done

```

I found it here.

----------

## dsd

broken link (403):

http://cknoerle.homelinux.org/nx9000/stuff/acpi/acpi-2004.02.12.tgz

----------

## friday

I fixed the broken link. Thanks dsd.

The file just had wrong permissions.

----------

## MaGuS

Hi,

since I am using speedfreqd and I had no use for the "dynamic" level I tried this:

```

battery ()

{

   if grep -q discharging $BAT_STATE

   then

      BAT_REMAIN=`awk '/remaining/ { print $3 }' $BAT_STATE`

      BAT_FULL=`awk '/last/ { print $4 }' $BAT_INFO`

      let "BAT_HALF=($BAT_FULL / 2 )"

      if (($BAT_REMAIN < $BAT_HALF))

      then

      $SPEEDFREQ -p powersave

   fi

      if (($BAT_REMAIN < `awk '/warning/ { print $4 }' $BAT_INFO`))

      then

         $LOGGER "battery capacity is critically low"

echo "System is going down!" > /dev/speech

         btn_pwr

      fi

   fi

}

```

I could not test it because my battery is full at the moment, but it should work. 

If the battery level is 1/2 of the last full level it will go into powersave modus, before it use the dynamic one.

For speechd look at this topic. I use it for other events, too.

Update:

The boot Script:

```

#!/bin/bash

#

# /etc/acpi/on_boot.sh (2004.01.17)

# called on boot to check for AC Adapter

# Christopher Knoerle <cknoerle@gmx.net>

#

# This works with gentoo-sources, ac-sources, mm-sources on my

# HP Compaq nx9000 Laptop. For more information have a look at

# http://cknoerle.homelinux.org/nx9000/

# The latest version is available from

# http://cknoerle.homelinux.org/nx9000/stuff/acpi/

# This should be placed in /etc/acpi/on_boot.sh and should be called

# through /etc/conf.d/local.start

# You can achieve this by doing the following:

# echo "/etc/acpi/on_boot.sh" >> /etc/conf.d/local.start

# lets set some paths

LOGGER="/usr/bin/logger -t ACPID" # logs to syslog - an echo logs to /var/log/acpid

XGAMMA="/usr/X11R6/bin/xgamma"

XSET="/usr/X11R6/bin/xset"

LAPTOPMODE="/sbin/laptopmode"

HDPARM="/sbin/hdparm"

SPEEDFREQ="/usr/bin/speedfreq"

BAT_STATE="/proc/acpi/battery/BAT1/state"

BAT_INFO="/proc/acpi/battery/BAT1/info"

#test for ac

if grep -q 'off-line' /proc/acpi/ac_adapter/ADP1/state

then

   $LOGGER "AC Adapter plugged OUT"

   if ps -A | grep -q X

   then

      $XGAMMA -d 0:0 -gamma 0.7 # set gamma in X to 70%

      $XSET -d 0:0 dpms 0 0 120 # shutdown display after 120s

   fi

   $LAPTOPMODE start # start laptop-mode

   $HDPARM -S 4 /dev/hda > /dev/null 2>&1 # spindown after 20s

   $HDPARM -B 1 /dev/hda > /dev/null 2>&1 # enable drives's APM

   

      BAT_REMAIN=`awk '/remaining/ { print $3 }' $BAT_STATE`

      BAT_FULL=`awk '/last/ { print $4 }' $BAT_INFO`

      let "BAT_HALF=($BAT_FULL / 2 )"

      if (($BAT_REMAIN < $BAT_HALF))

      then

      $LOGGER "Battery under half capacity (powersave mode)"

      $SPEEDFREQ -p powersave

      echo "powersave modus" > /dev/speech

   else

      $LOGGER "Battery over half capacity (dynamic mode)"

      $SPEEDFREQ -p dynamic

      echo "dynamic modus" > /dev/speech

   fi

   # not needed anymore - use powernowd

   #echo -n 1:0 > /proc/acpi/processor/CPU0/limit # set cpu performance state 1, throttling to 0

else

   $SPEEDFREQ -p performance

   exit 0

fi

# EOF 

```

Best regards,

Magnus

----------

## Kovid

I made some modifications to Chris' script, mainly to improve KDE compatibility. It will now cycle through all users till it finds a user running kdesktop and call dcop only for that user. 

Also I want to be able to handle the case when the Xserver is started after the ac adapter is unplugged, so I have modified acad_out and put a call to it in the battery state handler. This also removes the neccessity for the on_boot.sh script

```

source /etc/profile # for KDEDIR definition

DCOP=$KDEDIR/bin/dcop

KDE_USER="" # The user with a running KDE desktop

if [ -x $DCOP ]; then

  for user in $(users); do

    $DCOP --user $user kdesktop > /dev/null 2>&1

    if [ $? = 0 ]; then

      KDE_USER=$user

    fi

  done

fi

btn_pwr () { 

  $LOGGER "Powerbutton pressed"  

  if [ -n $KDE_USER ]; then  

    $DCOP --user $KDE_USER ksmserver ksmserver logout 1 2 0 && exit 0 

  else 

    $LOGGER "shutdown initiated" 

    /sbin/poweroff 

  fi 

}

# AC Adapter plugged in 

AC_OUT=""

acad_in () {

  $LOGGER "AC Adapter plugged IN" 

  ps -A | grep -q X

  if [ $? = 0 ]; then

    $XGAMMA -d 0:0 -gamma 1.0 # set gamma in X to 100% 

    $XSET -d 0:0 dpms 0 0 600 # shutdown display after 600s 

  fi 

   $HDPARM -S 240 /dev/hda > /dev/null 2>&1 # spindown after 20min 

   $HDPARM -B 255 /dev/hda > /dev/null 2>&1 # disable drive's APM 

   AC_OUT=""

} 

 

 

# AC Adapter plugged out 

# The X part is always called since the X server may be started up after adapter is unplugged

# To handle this a call to acad_out has been placed in the battery even handler 

acad_out () {

  ps -A | grep -q X

  if [ $? = 0 ]; then 

    $XGAMMA -d 0:0 -gamma 0.6 # set gamma in X to 70% 

    $XSET -d 0:0 dpms 0 0 120 # shutdown display after 120s 

  fi

  if [ -z AC_OUT ]; then

    $LOGGER "AC Adapter plugged OUT"

    $HDPARM -S 4 /dev/hda > /dev/null 2>&1 # spindown after 20s 

    $HDPARM -B 1 /dev/hda > /dev/null 2>&1 # enable drives's APM 

    AC_OUT="done"

  fi

} 

 

# state of battery changed 

# shutdown if battery capacity is low 

BAT_LOW=""

BAT_CRIT=""

battery () {

  grep -q discharging $BAT_STATE || grep -q unknown $BAT_STATE

  if [ $? = 0 ]; then 

    acad_out

    BAT_REMAIN=$(awk '/remaining/ { print $3 }' $BAT_STATE)

    BAT_WARNING=$(awk '/warning/  { print $4 }' $BAT_INFO)

    BAT_CRITICAL=$(awk '/low/     { print $4 }' $BAT_INFO)

    if [ $BAT_REMAIN -lt $BAT_CRITICAL -a -z $BAT_CRIT ]; then

      BAT_CRIT="notified"

      if [ -n $KDE_USER ]; then

        $DCOP --user $KDE_USER knotify Notify notify notify Me "Battery Critical. Poweroff strongly recommended." nosound nofile 2 0

      else

        $LOGGER "Battery capacity is critical" 

      fi

    else 

      if [ $BAT_REMAIN -lt $BAT_WARNING -a -z $BAT_LOW ]; then

        BAT_LOW="notified"

        if [ -n $KDE_USER ]; then

          $DCOP --user $KDE_USER knotify Notify notify notify Me "Battery Low. Poweroff recommended." nosound nofile 2 0

        else

          $LOGGER "Battery capacity is critical"

        fi

      fi

    fi

  fi

} 

 

```

----------

## kambrian

I am having a problem with this.  If I just close the lid, the monitor stays on.  If I push the button to close the lid and then manually check the state of monitor in /proc, the backlight turns off.  Here is the log from /var/log/acpid

[Sat Feb 21 11:01:10 2004] received event "button/lid LID 00000080 0000000a"

[Sat Feb 21 11:01:10 2004] executing action "/etc/acpi/default.sh button/lid LID

 00000080 0000000a"

[Sat Feb 21 11:01:10 2004] BEGIN HANDLER MESSAGES

[Sat Feb 21 11:01:10 2004] END HANDLER MESSAGES

[Sat Feb 21 11:01:10 2004] action exited with status 0

[Sat Feb 21 11:01:10 2004] executing action "/etc/acpi/actions.sh button/lid LID

 00000080 0000000a"

[Sat Feb 21 11:01:10 2004] BEGIN HANDLER MESSAGES

/etc/acpi/actions.sh: line 10: echo####NO ACTION FOR EVENT: : command not found

[Sat Feb 21 11:01:10 2004] END HANDLER MESSAGES

[Sat Feb 21 11:01:10 2004] action exited with status 1

[Sat Feb 21 11:01:10 2004] completed event "button/lid LID 00000080 0000000a"\

Any ideas?

----------

## squash_buckler

hei,

I have the file laptop-mode.txt in my kernel (/usr/src/linux/Documentation/laptop-mode.txt) but I dont have the file /sbin/laptop-mode.

How do I create it? I found the kernel patch in here

[url] ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.2-rc1/2.6.2-rc1-mm1/broken-out/laptop-mode-2.patch[/url]

but I don't know which part of it to copy to /sbin/laptop-mode

Can someone help me?

Thanks, Nadi

----------

## noneckturtle

I'm having problems getting ACPI to work. If I do cat /proc/acpi/event I get cat: /proc/acpi/event: Device or resource busy.

Anyone got eny ideas?

NOTE: acpid is installed = acpid-1.0.2-r2

            kernel is = gentoo-sources-2.4.25-r2

ACPI is compiled into the kernel

??????? I've no clue what to do from here?

----------

## friday

noneckturtle:

I guess you have acpid running. So after '/etc/init.d/acpid stop' you should be able to 'cat /proc/acpi/event'.

squash_buckler:

AFAIR the script is inside laptop_mode.txt. Just copy and paste to /sbin/laptop-mode

----------

## noneckturtle

friday,

I followed your instructions and the following happend:

glaptop portage # /etc/init.d/acpid stop

 * WARNING:  you are stopping a boot service.

 * Stopping acpid...                                                                                                    [ ok ]

glaptop portage # cat /proc/acpi/event

cat: /proc/acpi/event: Device or resource busy

I then tried restarting ACPID so that I could check the log file and this happend:

glaptop distfiles # /etc/init.d/acpid restart

 * Starting acpid...

acpid: can't open /proc/acpi/event: Device or resource busy               [ !! ]

Anyone got any ideas????

----------

## friday

noneckturtle:

Probably the acpid is still running.

To verify try one of the following:

```
ps -A | grep acpi
```

```
pidof acpid
```

If it is still running you can stop it by simply killing it:

```
killall acpid
```

or

```
kill `pidof acpid`
```

----------

## noneckturtle

Any ideas what I would need to do to set eth0 to be brought down when I close the lid + brought up when I open the lid?

EDITED::

Forgot to say that I want to do this with an onboard network (eth0) and a PCMCIA network card (eth1)

Any ideas would be appreciated.

----------

## quantumwire

When my AC Adapter is plugged OUT or IN I recive only one event per time in /proc/acpi/event.

For example if I plug OUT and IN my AC adapter several times I recive this events:

1 - plug OUT

```

hotkey HOTK 00000057 00000000

hotkey HOTK 00000069 00000000

```

2 - plug IN

```

hotkey HOTK 00000058 00000000

hotkey HOTK 00000069 00000001

```

3 - plug OUT

```

hotkey HOTK 00000057 00000001

hotkey HOTK 00000069 00000002

```

4 - plug IN

```

hotkey HOTK 00000058 00000001

hotkey HOTK 00000069 00000003

```

5 - plug OUT

```

hotkey HOTK 00000057 00000002

hotkey HOTK 00000069 00000004

```

and so on...

Note:

1 - if I wait 2 hours between step 3 and 4, for example, no more events are send to the event file in /proc/acpi.

2 - battery status is correctly reported on /proc/acpi/battery/BAT0/state... it means that I can see the battery is discharging etc... everything is fine here.

So in my case the battery scripts doesn't work because tha status check is done only one time.

Any idea?

[ASUS L5830 (L5C) - gentoo kernel 2.4.25 r2]

----------

## wickwire

Hi there,

I own a Compaq Presario 731PT and I've been searching for ways to get automatic shutdown/power-off on low battery and shutting down using the Power Button - here's a big thanks to friday for the script, it solved everything neatly in one go - I only had to change BAT1 to BAT0 - thanks once again, great help!!  :Very Happy: 

Next stop: trying to use those shortcut keys for email client and web browser...!  :Wink: 

----------

## groovec

i have a problem with the ac_adapter, i get no event when im plug it in and out

lid and powerbutten both work :

```
[Tue Jul 20 14:52:00 2004] received event "button/lid LID 00000080 00000001"

[Tue Jul 20 14:52:00 2004] executing action "/etc/acpi/action.sh button/lid LID 00000080 00000001"

[Tue Jul 20 14:52:00 2004] BEGIN HANDLER MESSAGES

[Tue Jul 20 14:52:01 2004] END HANDLER MESSAGES

[Tue Jul 20 14:52:01 2004] action exited with status 0

[Tue Jul 20 14:52:01 2004] completed event "button/lid LID 00000080 00000001"

[Tue Jul 20 14:52:01 2004] received event "button/lid LID 00000080 00000002"

[Tue Jul 20 14:52:01 2004] executing action "/etc/acpi/action.sh button/lid LID 00000080 00000002"

[Tue Jul 20 14:52:01 2004] BEGIN HANDLER MESSAGES

[Tue Jul 20 14:52:01 2004] END HANDLER MESSAGES

[Tue Jul 20 14:52:01 2004] action exited with status 0

[Tue Jul 20 14:52:01 2004] completed event "button/lid LID 00000080 00000002"

```

but when i plug the ac adapter in and out i only get the battery discharging event:

```
[Tue Jul 20 14:54:04 2004] received event "battery BAT1 00000080 00000001"

[Tue Jul 20 14:54:04 2004] executing action "/etc/acpi/action.sh battery BAT1 00000080 00000001"

[Tue Jul 20 14:54:04 2004] BEGIN HANDLER MESSAGES

[Tue Jul 20 14:54:04 2004] END HANDLER MESSAGES

[Tue Jul 20 14:54:04 2004] action exited with status 0

[Tue Jul 20 14:54:04 2004] completed event "battery BAT1 00000080 00000001"

[Tue Jul 20 14:54:04 2004] received event "battery BAT1 00000081 00000001"

[Tue Jul 20 14:54:04 2004] executing action "/etc/acpi/action.sh battery BAT1 00000081 00000001"

[Tue Jul 20 14:54:04 2004] BEGIN HANDLER MESSAGES

#### NO ACTION FOR EVENT:

[Tue Jul 20 14:54:04 2004] END HANDLER MESSAGES

[Tue Jul 20 14:54:04 2004] action exited with status 1

[Tue Jul 20 14:54:04 2004] completed event "battery BAT1 00000081 00000001"

[Tue Jul 20 14:54:23 2004] received event "battery BAT1 00000080 00000001"

[Tue Jul 20 14:54:23 2004] executing action "/etc/acpi/action.sh battery BAT1 00000080 00000001"

[Tue Jul 20 14:54:23 2004] BEGIN HANDLER MESSAGES

[Tue Jul 20 14:54:23 2004] END HANDLER MESSAGES

[Tue Jul 20 14:54:23 2004] action exited with status 0

[Tue Jul 20 14:54:23 2004] completed event "battery BAT1 00000080 00000001"

[Tue Jul 20 14:54:23 2004] received event "battery BAT1 00000081 00000001"

[Tue Jul 20 14:54:23 2004] executing action "/etc/acpi/action.sh battery BAT1 00000081 00000001"

[Tue Jul 20 14:54:23 2004] BEGIN HANDLER MESSAGES

#### NO ACTION FOR EVENT:

[Tue Jul 20 14:54:23 2004] END HANDLER MESSAGES

[Tue Jul 20 14:54:23 2004] action exited with status 1

[Tue Jul 20 14:54:23 2004] completed event "battery BAT1 00000081 00000001"

```

/proc/acpi/ac_adapter/ACAD/state gives me the correct status, so kernel support should be right

----------

## Nicolinux

Hi,

I am using this set of scripts with great success. One questions remains. How do I hunt/minimize the processes that make my harddrive spinup shortly after it has spindown? It make this nice feature pointless since the wearoff effect for the hard drive that keeps spin up and down defeats the advantage of longer batery life.

Thanks

Stefan

----------

