[solved] cli-power-manager (autoshutdown)
Forum rules
We don't support installations in VirtualBox, VMWare, qemu or others. We ignore posts about WINE, PlayOnLinux, Steam and Skype. We don't support btrfs, lvm, UEFI, side-by-side installations with GPT or dualboot with anything newer than Windows XP.
Google your problem first. Check the Wiki. Read the existing threads. It's okay to "hijack" an existing thread, yes! If your problem is not yet covered, open a new thread. To get the quickest possible help, mention the exact release codename in your post (uname -a is a good idea, too). Due to the lack of crystal balls, attach the output of lspci -nnk if you encounter hardware problems.
We don't support installations in VirtualBox, VMWare, qemu or others. We ignore posts about WINE, PlayOnLinux, Steam and Skype. We don't support btrfs, lvm, UEFI, side-by-side installations with GPT or dualboot with anything newer than Windows XP.
Google your problem first. Check the Wiki. Read the existing threads. It's okay to "hijack" an existing thread, yes! If your problem is not yet covered, open a new thread. To get the quickest possible help, mention the exact release codename in your post (uname -a is a good idea, too). Due to the lack of crystal balls, attach the output of lspci -nnk if you encounter hardware problems.
[solved] cli-power-manager (autoshutdown)
hello there script-gurus
once in a while, i left my laptop on unplugged till the battery drop. (fall asleep or stuff)
when comes to GUI, there's some choices of using power manager to auto shutdown or hibernate when the battery has reach some amount of level predefined.
but what about cli?
to monitoring the battery level maybe i can run
$ watch --interval=xx acpi
is there any how-to's to auto shutdown when battery is critical, say 5% in cli environtment?
thanks in advance
once in a while, i left my laptop on unplugged till the battery drop. (fall asleep or stuff)
when comes to GUI, there's some choices of using power manager to auto shutdown or hibernate when the battery has reach some amount of level predefined.
but what about cli?
to monitoring the battery level maybe i can run
$ watch --interval=xx acpi
is there any how-to's to auto shutdown when battery is critical, say 5% in cli environtment?
thanks in advance
Last edited by mamaw on Fri Oct 11, 2013 5:05 am, edited 1 time in total.
it all begin from curiousity
-
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
- Contact:
Re: cli-power-manager
Hello,
yes, that should be possible. Just quickly confirming,
is the value we need, now the question is only: how much is 5%
We have a value 'full' coming from
So, we could write a start service (in /etc/rc5.d/) that is executed every 600 seconds (10 minutes), which reads the energy_now value, and as soon as it falls below a level, a xmessage pops up to save all documents and then, again after 90 seconds, to shutdown.
Just an idea.
yes, that should be possible. Just quickly confirming,
Code: Select all
cat /sys/class/power_supply/BAT0/energy_now
We have a value 'full' coming from
Code: Select all
cat /sys/class/power_supply/BAT0/energy_full_design
Just an idea.
..gnutella..
-
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
- Contact:
Re: cli-power-manager
Who is our friend? Google. "monitor battery debian no-X" brings http://blog.sleeplessbeastie.eu/2013/01 ... -capacity/
There are quite some ideas, just the paths have to be changed a bit. See the "RRDtool" part, where he uses 'watch' to read the output of a script. The script would only grep/echo the energy_now value, which needs to be played with.
There are quite some ideas, just the paths have to be changed a bit. See the "RRDtool" part, where he uses 'watch' to read the output of a script. The script would only grep/echo the energy_now value, which needs to be played with.
..gnutella..
-
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
- Contact:
Re: cli-power-manager
Here's a solution using conky: http://linuxmintdebian.blogspot.com/200 ... rning.html
Instead of conky, make a watch line in /etc/rc.local that calls the 'warn-shutdown' script (which is executable and with the right permissions)
Instead of conky, make a watch line in /etc/rc.local that calls the 'warn-shutdown' script (which is executable and with the right permissions)
..gnutella..
Re: cli-power-manager
thanks MB, i will tinker with it a bit.
i did ask uncle google several times, but i guess i miss the right keyword :(
i did ask uncle google several times, but i guess i miss the right keyword :(
it all begin from curiousity
-
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
- Contact:
Re: cli-power-manager
People will anally rape me for saying this, but I use a certain email address to log in to Google Services, and it seems to me that after a while the search engine learns which kind of posts should be displayed first. After having used this service for several months, I must say that it has convinced me, even though the privacy-sensitive readers already prepare the vaseline for me.
..gnutella..
Re: cli-power-manager
privacy is bloat.
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.
Re: cli-power-manager
i've used conky solution for coloring the batt percentage when low. Still miss it sometimes though.
google is very dissappointed in my offerings.
google is very dissappointed in my offerings.
Work hard; Complain less
-
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
- Contact:
Re: cli-power-manager
One could send the warning to dunst (or any other notifier daemon), or send a beep, play a sound file, open an xmessage, or make the keyboard indicators blink.
..gnutella..
- ivanovnegro
- Minister of Truth
- Posts: 5450
- Joined: Wed Oct 17, 2012 11:12 pm
Re: cli-power-manager
:D It is true Jules. It works like spam filters.machinebacon wrote:I must say that it has convinced me, even though the privacy-sensitive readers already prepare the vaseline for me.
Re: cli-power-manager
so, finally ... (how many days already?)
with my zero knowledge of bash :D #laugh
i managed to write this first bash script of mine:
this required passw, so i add to visudo
%sudo ALL=NOPASWWD: /sbin/shutdown
and this solved it. cheers..
----------------------------------------
i believe the script is far from "proper" ;)
with my zero knowledge of bash :D #laugh
i managed to write this first bash script of mine:
Code: Select all
#!/bin/bash
while true
do
bat1=500000 #or any (critical) battery value
bat2=`cat /sys/class/power_supply/BAT1/energy_now`
sleep 5s
if [ "$bat1" -gt "$bat2"] ; then
sudo shutdown -h now
fi
done
this required passw, so i add to visudo
%sudo ALL=NOPASWWD: /sbin/shutdown
and this solved it. cheers..
----------------------------------------
i believe the script is far from "proper" ;)
it all begin from curiousity
Re: [solved] cli-power-manager (autoshutdown)
a little update, to show the percentage of the battery from tmux :p
the output:
44.03% Discharging
*i login to openbox for a while since i miss those colorfull pic instead of:
Google
[___________________________________] Advanced search Language tools
[Google Search] [I'm Feeling Lucky]
Code: Select all
#!/bin/bash
red='\e[0;31m'
yellow='\e[1;33m'
NC='\e[0m'
bat1=3500000
bat3=`cat /sys/class/power_supply/BAT1/energy_full_design`
while true
do
clear
bat2=`cat /sys/class/power_supply/BAT1/energy_now`
bat4=`echo "scale=2;($bat2*100)/$bat3" | bc`
stat=`cat /sys/class/power_supply/BAT1/status`
echo $bat4"%" $stat
sleep 5s
if [ "$bat1" -gt "$bat2" ] ; then
clear
echo -e $bat4"% ${yellow}Critical Battery${NC}"
echo -e "Press ${red}'ctrl+c'${NC} to skip shutdown. Shutdown in 60 second..."
sleep 60s
sudo shutdown -h now
exit 1
fi
done
44.03% Discharging
*i login to openbox for a while since i miss those colorfull pic instead of:
[___________________________________] Advanced search Language tools
[Google Search] [I'm Feeling Lucky]
it all begin from curiousity
-
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
- Contact:
Re: [solved] cli-power-manager (autoshutdown)
^sweet ;)
You can try, in TTY without tmux:
xlinks2 google.com
There you have your colorful pic :)
You can try, in TTY without tmux:
xlinks2 google.com
There you have your colorful pic :)
..gnutella..