Gentoo Forums
Gentoo Forums
Quick Search: in
Battery script
View unanswered posts
View posts from last 24 hours

rackathon
 
Reply to topic    Gentoo Forums Forum Index Gentoo Chat
View previous topic :: View next topic  
Author Message
Riveri
n00b
n00b


Joined: 20 Feb 2004
Posts: 65
Location: Tampere, Finland

PostPosted: Tue Nov 23, 2004 4:22 pm    Post subject: Battery script Reply with quote

Ok, my problem is this: Im using laptop to run gentoo and its quite usual that my laptop shutdowns several times every week cause im forgetting to plug power cable back and the battery runs out.

I though that if there would be a script (or littleprogram) which checks battery's state and changes the wallpaper to something else (to bright red one for example) when it goes below 5%, it would help me to notice it.

My knowhow is too little on these things that i could do that kind of prog/script, but if someone has little sparetime or knows a program which can do the above one, i really would appreciate that.
Back to top
View user's profile Send private message
Archangel1
Veteran
Veteran


Joined: 20 Apr 2004
Posts: 1212
Location: Work

PostPosted: Tue Nov 23, 2004 4:36 pm    Post subject: Reply with quote

Interesting one... why not have a little battery monitor in some system tray type area?
Ala klaptopdaemon, no doubt XFCE has some similar dockapp thing, or you could use gkrellm/gdesklets or something along those lines to monitor it?
Back to top
View user's profile Send private message
Riveri
n00b
n00b


Joined: 20 Feb 2004
Posts: 65
Location: Tampere, Finland

PostPosted: Tue Nov 23, 2004 4:50 pm    Post subject: Reply with quote

yep... tried those (torsmo, gdesklet and gkrellm for example)... just too small... :( and those usually goes under other windows

but if the whole wallpaper would change i think i would notice that :)
dont want anykind of sound alarms... cause i dont keep my sounds on always

oh... and im using acpi...
Back to top
View user's profile Send private message
mangaf
n00b
n00b


Joined: 20 Feb 2003
Posts: 6

PostPosted: Tue Nov 23, 2004 5:23 pm    Post subject: Reply with quote

with klaptop you have options to launch a command and some options more, at two leves of battery charge
Back to top
View user's profile Send private message
Riveri
n00b
n00b


Joined: 20 Feb 2004
Posts: 65
Location: Tampere, Finland

PostPosted: Tue Nov 23, 2004 5:26 pm    Post subject: Reply with quote

klaptop is kde program ?

im using fvwm
Back to top
View user's profile Send private message
denstark
l33t
l33t


Joined: 02 Jun 2003
Posts: 647
Location: bos.ma.us

PostPosted: Tue Nov 23, 2004 5:28 pm    Post subject: Reply with quote

Riveri wrote:
klaptop is kde program ?

im using fvwm


Well, that doesn't mean you won't be able to use it. You will, however, have to install all that kde crap.
_________________
lol, its my blog.
penguinparty.org
Quote:
< denstark> rws: why do you have to be so indian
< rws> can't help it. I am brown and poor.
Back to top
View user's profile Send private message
BlackEdder
Veteran
Veteran


Joined: 26 Apr 2004
Posts: 2568
Location: Dutch enclave in Egham, UK

PostPosted: Tue Nov 23, 2004 5:29 pm    Post subject: Reply with quote

The info about your battery status is somewhere in /proc/acpi. I've no laptop so cn't check where precisely, but it should be super easy to write a script that checks the battery every minute and based on output sets your background. Info that is needed for that is mainly which program you are using to set your background now.. and where the info in acpi precisely is.
Back to top
View user's profile Send private message
Riveri
n00b
n00b


Joined: 20 Feb 2004
Posts: 65
Location: Tampere, Finland

PostPosted: Tue Nov 23, 2004 5:36 pm    Post subject: Reply with quote

AFAIK needed info is in two places
remaining capacity and design capacity

Code:

rave rave # cat /proc/acpi/battery/BAT0/state
present:                 yes
capacity state:          ok
charging state:          discharging
present rate:            unknown
remaining capacity:      4268 mAh
present voltage:         14800 mV
rave rave # cat /proc/acpi/battery/BAT0/info
present:                 yes
design capacity:         4400 mAh
last full capacity:      4400 mAh
battery technology:      rechargeable
design voltage:          14800 mV
design capacity warning: 440 mAh
design capacity low:     176 mAh
capacity granularity 1:  264 mAh
capacity granularity 2:  3960 mAh
model number:            BAT0
serial number:           236
battery type:            Lion
OEM info:                SANYO   


im using now fbsetbg for setting bg
Back to top
View user's profile Send private message
Riveri
n00b
n00b


Joined: 20 Feb 2004
Posts: 65
Location: Tampere, Finland

PostPosted: Tue Nov 23, 2004 5:42 pm    Post subject: Reply with quote

denstark wrote:
Riveri wrote:
klaptop is kde program ?

im using fvwm


Well, that doesn't mean you won't be able to use it. You will, however, have to install all that kde crap.


that's what i was afraid of..
Back to top
View user's profile Send private message
denstark
l33t
l33t


Joined: 02 Jun 2003
Posts: 647
Location: bos.ma.us

PostPosted: Tue Nov 23, 2004 5:48 pm    Post subject: Reply with quote

Seems very easy to do, but i don't know the proper way to cut the numbers from the text sring and then convert it to a numeric variable (i think I could be wrong)....

other than that, it should be very easy.
_________________
lol, its my blog.
penguinparty.org
Quote:
< denstark> rws: why do you have to be so indian
< rws> can't help it. I am brown and poor.
Back to top
View user's profile Send private message
BlackEdder
Veteran
Veteran


Joined: 26 Apr 2004
Posts: 2568
Location: Dutch enclave in Egham, UK

PostPosted: Tue Nov 23, 2004 5:54 pm    Post subject: Reply with quote

I can do it for you in a ruby script.. don't know enough about bash scripting to do it easy in there

Or you can use (battery part) of this script:
http://forums.gentoo.org/viewtopic.php?t=80077&highlight=battery+bash
Back to top
View user's profile Send private message
InfinityX
Guru
Guru


Joined: 31 Jan 2004
Posts: 385

PostPosted: Tue Nov 23, 2004 6:29 pm    Post subject: Reply with quote

This seems to work well on my laptop:

Code:
#!/bin/bash

declare -i battery

battery=`acpi | cut -d '%' -f1 | cut -d ',' -f2 | tr -d '\n'`

if [[ "$battery" < "5" ]]
then
        fbsetbg red.jpg
fi


You'll need to emerge acpi, and the syntax may be slightly different for your laptop.
Back to top
View user's profile Send private message
Riveri
n00b
n00b


Joined: 20 Feb 2004
Posts: 65
Location: Tampere, Finland

PostPosted: Tue Nov 23, 2004 7:05 pm    Post subject: Reply with quote

/usr/bin/battery
Code:

#!/bin/bash
                                                                               
path="/proc/acpi/battery/BAT0"
 
full=`cat $path/info|grep 'last full capacity'|awk -F: '{print $2}'|awk -Fm '{print $1}'`
current=`cat $path/state|grep 'remaining capacity'|awk -F: '{print $2}'|awk -Fm '{print $1}'`
state=$(( current * 100 / $full))

echo "$state"


~/battery
Code:

#!/bin/bash

declare -i battery

battery=`/usr/bin/battery`

if [[ "$battery" < "5" ]]
then
        fbsetbg -f /home/rave/wallpapers/red.jpg
fi


ok... it works...
now, what would be the best way to run it ? crontab ?
Back to top
View user's profile Send private message
nightm4re
Guru
Guru


Joined: 19 Jun 2004
Posts: 519
Location: Providence, RI, USA

PostPosted: Wed Nov 24, 2004 8:03 am    Post subject: Reply with quote

Riveri wrote:


ok... it works...
now, what would be the best way to run it ? crontab ?


yep.. prolly the easiest way to do it. set it up for like every 5 minutes or something.
_________________
Nitrogen - GtkMM based background setter/restorer, please test!
Minuslab | d.minuslab.net
Back to top
View user's profile Send private message
Riveri
n00b
n00b


Joined: 20 Feb 2004
Posts: 65
Location: Tampere, Finland

PostPosted: Wed Nov 24, 2004 1:50 pm    Post subject: Reply with quote

if [[ "$battery" < "5" ]] -> if [[ "$battery" < "05" ]]

and it works right....

anyway, thanks to all who bothered to help me!
Back to top
View user's profile Send private message
aerandir
n00b
n00b


Joined: 09 Jan 2004
Posts: 13
Location: Denmark

PostPosted: Sun Dec 05, 2004 8:25 am    Post subject: Reply with quote

if you are using gkrellm - you can define some extra alarms in the battery options - just set lower/alarm limit and any annoying little proggy youd like to get startet when the time comes :twisted:

but gotto go back playing with my freshly installed compaq armada :D
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo Chat All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum