LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 06-19-2011, 09:56 PM   #16
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749

Glad you got it working! I did mention the 'power' group in post#10 :-)

The power event is normally triggered by pressing the power button on your computer.

I like to set the lid switch action in /etc/acpi/acpi_handler.sh so that it works in all environments.
Code:
#!/bin/sh
# Default acpi script that takes an entry for all actions

IFS=${IFS}/
set $@

case "$1" in
  button)
    case "$2" in
      power) /sbin/init 0
         ;;
      lid) /usr/sbin/pm-hibernate
         ;;
      *) logger "ACPI action $2 is not defined"
         ;;
    esac
    ;;
  *)
    logger "ACPI group $1 / action $2 is not defined"
    ;;
esac
 
Old 12-16-2011, 02:38 AM   #17
tix
Member
 
Registered: May 2011
Posts: 31
Blog Entries: 6

Rep: Reputation: 1
Quote:
Originally Posted by narke View Post
Hi,


Below is a piece of copy from my /etc/acpi_handler.sh

...
case "$1" in
button)
case "$2" in
power) /sbin/init 0
/usr/bin/date >> /var/log/battery-log 2>&1
/usr/bin/acpitool -B >> /var/log/battery-log 2>&1
;;

*)
logger "ACPI group $1 / action $2 is not defined"
;;
esac
;;
...

But I never see the /var/log/battery-log exists in my file system and my laptop was running out of battery and got shutdown abnormally.

Is there something wrong in my acpi_handler.sh script?

-
narke

---------------------------

An important thing to note is that the way acpi handles events is:

1) event generated ---> passed to kernel --> kernel spews out event to file /etc/acpi/events/default

(contents of /etc/acpi/events/default)
event=.*
action=/etc/acpi/acpi_handler.sh %e

2) note that all events (i.e. event=.*) are sent to /etc/acpi/acpi_handler.sh

3) your script above is for /etc/acpi/acpi_handler.sh is only interested in the button events
the button event is generated when you press the power button on your computer


4) in older kernels the information for battery was stored in the "/proc/acpi/battery/" directory;
for newer kernels the information for battery is stored in "/sys/class/power_supply/" directory
in directory [BAT0] and/or [BAT1] depending how linux detects your batteries and the number of batteries on your systems

5) you can read the battery information from /proc/sys/class/power_supply/BAT0 directory (if you battery is detected as [BAT0])

6)using simple mathematics/arithmetic, you can actually run a shell (bash) script that can shutdown your laptop during low battery situations
when laptop is not being charged by A/C power

7) you can write information to log files (/var/log/messages) about low battery events using the script you develop for turning off your machine

For further reading about using ACPI statistics to turn off a laptop during low battery situations:

Goto (LOL!):
http://www.gen.horizon-host.com/linux.php

click on:
Configuring ACPI - Laptop Battery and Automatic Shutdown

Tix

"Blessed are the angry, for they shall inherit the national debt."
--
 
Old 12-17-2011, 10:18 AM   #18
dr.s
Member
 
Registered: Feb 2010
Distribution: Slackware64-current
Posts: 338

Rep: Reputation: 156Reputation: 156
You might find this command handy, it'll show what events are taking place, here's a sample
output.
Code:
$ acpi_listen 
button/lid LID0 00000080 00000005
button/lid LID0 00000080 00000006
battery BAT0 00000080 00000001
battery BAT0 00000080 00000001
...
^C
 
Old 12-19-2011, 03:33 AM   #19
tix
Member
 
Registered: May 2011
Posts: 31
Blog Entries: 6

Rep: Reputation: 1
Quote:
Originally Posted by dr.s View Post
You might find this command handy, it'll show what events are taking place, here's a sample
output.
Code:
$ acpi_listen 
button/lid LID0 00000080 00000005
button/lid LID0 00000080 00000006
battery BAT0 00000080 00000001
battery BAT0 00000080 00000001
...
^C
Thank you for your reply.

Unfortunately, ACPI will give you the same event of 00000080 and 00000001 when battery is critically low.
The information 00000080 and 00000001 as appears in systems logs (/var/log/messageas) is not very useful, i.e.:

logger: ACPI action battery for battery BAT0 is event 00000080 and 00000001

A more useful and meaningful output would be sending the battery level in % and using it to shutdown the computer
using the "shutdown" command, i.e.:

logger: Your battery level at 23 % is below 30 % which is low...system shutting down
logger: Your battery level at 18 % is below 30 % which is low...system shutting down
logger: Your battery level at 16 % is below 30 % which is low...system shutting down
logger: Your battery level at 14 % is below 30 % which is low...system shutting down
logger: Your battery level at 12 % is below 30 % which is low...system shutting down
shutdown[4822]: shutting down for system halt
init: Switching to runlevel: 0

C For Yourself:

Goto:
http://www.gen.horizon-host.com/linux.php
OR
http://www.gen.azok.org/linux.php

Click on:
Configuring ACPI - Laptop Battery and Automatic Shutdown

Tix


Politicians are the same everywhere. They promise
to build a bridge even where there is no river.
-- Nikita Khrushchev

Last edited by tix; 12-19-2011 at 03:58 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Power Issues, vanilla ubuntu kernel, (acpi etc) acpi -V outputs etc jamescondron Linux - Laptop and Netbook 1 02-16-2009 10:48 AM
how to detect system power event(user trigger),suspend,hibernate,resume...? minge.zu Linux - Desktop 1 02-11-2009 08:19 PM
Bypassing ACPI lid button event in X Erratio Linux - Laptop and Netbook 3 10-13-2008 12:12 PM
No acpi battery event on my asus laptop val3xiv Slackware 5 08-27-2008 10:31 AM
lid close generates no acpi event mannyzen76 Linux - Laptop and Netbook 0 02-21-2004 11:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 09:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration