LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 04-05-2008, 03:09 AM   #1
iiv
Member
 
Registered: Jun 2007
Location: Russia, Moscow Region
Distribution: Slackware
Posts: 167

Rep: Reputation: 30
Question laptop battery exhaust and shutdown


How can it be detected that the battery is near to be exhausted and to automatically shutdown laptop then?..
 
Old 04-05-2008, 03:53 AM   #2
willysr
Senior Member
 
Registered: Jul 2004
Location: Jogja, Indonesia
Distribution: Slackware-Current
Posts: 2,516

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
try to enable the battery modules and activate the battery monitor in KDE Control Panel (in case you are using KDE)
 
Old 04-05-2008, 02:43 PM   #3
iiv
Member
 
Registered: Jun 2007
Location: Russia, Moscow Region
Distribution: Slackware
Posts: 167

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by willysr View Post
try to enable the battery modules and activate the battery monitor in KDE Control Panel (in case you are using KDE)
Yeah, I've thought about this, but that's not the solution, because

1. I do not use KDE, I use XFce. Yes, there is a plugin, but that does not work always showing 50%% state, which actually means the plugin does not work. Contacted developers, but we had no luck in figuring why it does not work. But still even if I could make it possible, there is
2. The case when I'm not logged in, when no WM is running or the laptop could just be at console and not running X Window system at all.

So any other suggestions?
 
Old 04-05-2008, 04:10 PM   #4
T3slider
Senior Member
 
Registered: Jul 2007
Distribution: Slackware64-14.0
Posts: 2,244

Rep: Reputation: 622Reputation: 622Reputation: 622Reputation: 622Reputation: 622Reputation: 622
I don't have a laptop, so this won't be the best response, but you may wish to try the `acpi` command (after the proper modules have been loaded, like battery and ac and wonderful stuff I know nothing about). It'll output the battery status in the CLI. I'm sure a daemon could be designed around this (if it doesn't exist already). There may also be some way to set it up just using ACPI stuff -- but again, I know nothing about it. My battery checking experience comes from an embedded system that is totally different (I had to check a file in /proc), so I don't know if I'm being very helpful here. However, if there IS a way of doing this, it will most certainly revolve around ACPI.
 
Old 04-05-2008, 07:10 PM   #5
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Ruhr Area, Germany
Distribution: Slackware64 14.0
Posts: 1,517

Rep: Reputation: 90
You could do it manually of course. With my laptop I can get the value like this - I have NOT tested it intensively.

Code:
max=$(cat /proc/acpi/battery/BAT0/info | grep "last full" | rev | cut -d ' ' -f 2 | rev)
act=$(cat /proc/acpi/battery/BAT0/state | grep "remaining" | rev | cut -d ' ' -f 2 | rev)
echo $act / $max *100 | bc -l | cut -d "." -f 1
Maybe you have to grep for "design capacity" to get the max value, don't know what happens if you didn't fully load the battery the last time.
The code above will give a syntax error if there is no battery present.
 
Old 04-06-2008, 08:16 AM   #6
alkos333
Member
 
Registered: Dec 2006
Posts: 271

Rep: Reputation: 31
You could create a bash script, have it run in cron every 30 seconds and check for the remaining battery capacity. Once it's below a certain level, power it off.

What laptop you got?

Last edited by alkos333; 04-06-2008 at 08:17 AM.
 
Old 04-06-2008, 10:16 AM   #7
pdw_hu
Member
 
Registered: Nov 2005
Location: Budapest, Hungary
Distribution: Slackware, Gentoo
Posts: 346

Rep: Reputation: Disabled
The laptop-mode-tools utility (or rather: script) have good solutions to these. Google it.
 
Old 04-06-2008, 11:06 AM   #8
ak-87
Member
 
Registered: Apr 2005
Posts: 68

Rep: Reputation: 15
Quote:
Originally Posted by iiv View Post
Yes, there is a plugin, but that does not work always showing 50%% state...
I had the same problem on my old Toshiba with Arch Linux (after move to 2.6.21.x kernel). I had to load these modules in order to make battery plugin work properly - ac, battery, toshiba_acpi.

This page may be helpful to you - http://wiki.archlinux.org/index.php/Acpi_modules
 
Old 04-06-2008, 03:44 PM   #9
tommcd
Senior Member
 
Registered: Jun 2006
Location: Philadelphia PA USA
Distribution: Lubuntu, Slackware
Posts: 2,229

Rep: Reputation: 286Reputation: 286Reputation: 286
See the thread I started when I first put Slackware on my laptop:
http://www.linuxquestions.org/questi...lack12-574580/
See post #9. You need to modprobe:
Code:
ac, battery, button, dock, fan, processor, thermal, video
To enable battery monitor on bootup add a line for each of these to /etc/rc.d/rc.local

/sbin/modprobe ac
/sbin/modprobe battery
/sbin/modprobe button
etc....
You don't have to modprobe acpi. I didn't anyway.
 
Old 04-07-2008, 06:21 AM   #10
iiv
Member
 
Registered: Jun 2007
Location: Russia, Moscow Region
Distribution: Slackware
Posts: 167

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by alkos333 View Post
You could create a bash script, have it run in cron every 30 seconds and check for the remaining battery capacity. Once it's below a certain level, power it off.
Good solution, but not that efficient to run anything every N seconds.

Quote:
Originally Posted by alkos333 View Post
What laptop you got?
It is Asus M6NE.

Quote:
Originally Posted by pdw_hu View Post
The laptop-mode-tools utility (or rather: script) have good solutions to these. Google it.
Well, I assume that all this could be done through ACPI signals, so that we can get something like "WE_AGE_GOIND_TO_LOOSE_POWER" from acpid and it will execute whatever is /etc/acpi/loosing_power.sh if that happens.

Quote:
Originally Posted by ak-87 View Post
I had the same problem on my old Toshiba with Arch Linux (after move to 2.6.21.x kernel). I had to load these modules in order to make battery plugin work properly - ac, battery, toshiba_acpi.
I need more than to monitor the battery, I need to autoshutdown my laptop, in case it loses power and X is not running.
Monitoring battery status is a lot easier by
Code:
cat /sys/class/power_supply/BAT*/charge_now
Quote:
Originally Posted by tommcd View Post
You need to modprobe:
Code:
ac, battery, button, dock, fan, processor, thermal, video
Be sure, they are loaded. Again: I'm going more than to monitor the battery state, I'm already able to do that.

But still many thanks to everyone replied, you gave me several ideas.
 
Old 04-07-2008, 06:34 AM   #11
alkos333
Member
 
Registered: Dec 2006
Posts: 271

Rep: Reputation: 31
Quote:
Originally Posted by iiv View Post
Good solution, but not that efficient to run anything every N seconds.
Well this is essentially how a daemon works. It constantly does some kind of process in the background while it's running. You could set your interval to whatever you feel is more appropriate. If you can get the battery discharge status, this is pretty much all you have to do.

See if your battery module releases any information to the ACPI log. You can add an association script to /etc/acpi/events, that would look something like this:

Code:
event=<bettery life message from /var/log/acpid>
action=<script that would power off the machine if message is found>
This way you don't have to have a cron job blindly running every N seconds - ACPI will take care of monitoring.

Last edited by alkos333; 04-07-2008 at 06:38 AM.
 
Old 04-07-2008, 11:06 AM   #12
ak-87
Member
 
Registered: Apr 2005
Posts: 68

Rep: Reputation: 15
Quote:
Originally Posted by iiv View Post
I need more than to monitor the battery, I need to autoshutdown my laptop, in case it loses power and X is not running.
I hope I understood you well... There are some options in XFCE's battery plugin properties that can run certain command if battery is exhausted. For example, if "critical battery" percentage is 2% - run "halt" command.
 
Old 04-07-2008, 01:03 PM   #13
iiv
Member
 
Registered: Jun 2007
Location: Russia, Moscow Region
Distribution: Slackware
Posts: 167

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by alkos333 View Post
Well this is essentially how a daemon works. It constantly does some kind of process in the background while it's running. You could set your interval to whatever you feel is more appropriate.
No, good daemons don't run this way, they do it much smarter Actually, it is not a good idea to do anything "every N seconds". For example FTP daemon does not ask the system if someone requested connection within past 10 seconds.


Quote:
Originally Posted by alkos333 View Post
See if your battery module releases any information to the ACPI log. You can add an association script to /etc/acpi/events, that would look something like this:

Code:
event=<bettery life message from /var/log/acpid>
action=<script that would power off the machine if message is found>
This way you don't have to have a cron job blindly running every N seconds - ACPI will take care of monitoring.
Well, this is what I am seeking for. The exact name of ACPI signal, or the documentation for it. Looked into /usr/src/linux/power, but found nothing on this.

Quote:
Originally Posted by ak-87 View Post
I hope I understood you well... There are some options in XFCE's battery plugin properties that can run certain command if battery is exhausted. For example, if "critical battery" percentage is 2% - run "halt" command.
The key words were "X is not running" -- no graphical interface is on.
 
Old 04-07-2008, 11:49 PM   #14
alkos333
Member
 
Registered: Dec 2006
Posts: 271

Rep: Reputation: 31
[QUOTE=iiv;3113701]No, good daemons don't run this way, they do it much smarter Actually, it is not a good idea to do anything "every N seconds". For example FTP daemon does not ask the system if someone requested connection within past 10 seconds.
[QUOTE=iiv;3113701]

If you would like to get technical, sure. The idea, however, is the same - some constant process running in the background.
 
Old 12-16-2011, 02:27 AM   #15
tix
LQ Newbie
 
Registered: May 2011
Posts: 24

Rep: Reputation: 0
In newer kernels for Slackware Linux, the location of the battery information has been changed from /proc directory to /sys directory. This may be applicable also for other systems.

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.

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."
--
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
HP nx6110 shutdown freeze when on battery during session jirik Linux - Laptop and Netbook 1 05-20-2006 01:02 PM
laptop battery support kurrupt Linux - Laptop and Netbook 0 01-29-2005 12:25 AM
Laptop Battery monitor amjith Yoper 5 10-06-2004 02:14 PM
Charge battery for laptop mikeshn Linux - Hardware 5 04-26-2004 07:16 AM
Laptop Battery tinesthai Linux - Hardware 0 01-12-2003 09:42 PM


All times are GMT -5. The time now is 08:54 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration