LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Laptop and Netbook
User Name
Password
Linux - Laptop and Netbook Having a problem installing or configuring Linux on your laptop? Need help running Linux on your netbook? This forum is for you. This forum is for any topics relating to Linux and either traditional laptops or netbooks (such as the Asus EEE PC, Everex CloudBook or MSI Wind).

Notices


Reply
  Search this Thread
Old 08-07-2013, 12:26 AM   #1
steak1987
Member
 
Registered: Jan 2012
Posts: 130

Rep: Reputation: Disabled
Question Battery Benchmark in linux


Im trying to see how well my battery runs and lasts in real life scenarios, but I cant seem to find any applications or tools or scripts in linux. I can understand that one option is loading a long (10h) youtube video or a long video playlist of its offline, but I cant leave them running, I need to be there to time when the power finally goes.

Ive got powertop and I tried looking at the help and cooking up a command:

Code:
XXXX@XXXX-Latitude-D430 ~ $ powertop --help
Usage: powertop [OPTIONS]

--debug 		 run in "debug" mode
--version 		 print version information
--calibrate 		 runs powertop in calibration mode
--extech[=devnode] 	 uses an Extech Power Analyser for measurements
--html[=FILENAME] 	 generate a html report
--csv[=FILENAME] 	 generate a csv report
--time[=seconds] 	 generate a report for 'x' seconds
--iteration[=iterations] number of times to run each test
--workload[=workload] 	 file to execute for workload
--quite 	 supress stderr output
--help 			 print this help menu

For more help please refer to the README

XXXX@XXXX-Latitude-D430 ~ $ sudo powertop -html[=/home/XXXX/batt.html] --time[=5]
powertop: unrecognised option '--time[=5]'
XXXX@XXXX-Latitude-D430 ~ $ sudo powertop -html[=/home/XXXX/batt.html]
Loaded 361 prior measurements
Preparing to take measurements
Taking 1 measurement(s) for a duration of 20 second(s) each.
Cannot open output file tml[=/home/XXXX/batt.html (No such file or directory)
PowerTOP outputing using base filename tml[=/home/XXXX/batt.html
XXXX@XXXX-Latitude-D430 ~ $
It didnt help ... :-/

Ive did some looking:

http://www.google.com.au/?gws_rd=cr#...tery+benchmark

http://www.mail-archive.com/linux-la.../msg01290.html

Somebody apparently asked the same question in 1999 but I cant seem to find the answer so far ....

A simmilar tool exists in windows:
http://www.batteryeater.com/support.html



Does anybody have any idea ?
 
Old 08-07-2013, 12:33 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
I have not used powertop, but it happens that within the past few days I wote short cron script to log battery state to a MySQL database, once per minute in my case.

I can then query that data to see fine grained charge and discharge data for as long a period as I like. I have not written any special methods for viewing the data, I just query it and pipe into gnuplot at this time.

If interested I'll post the script and the DB table structure, and tell you how to get it running... then you are on your own.
 
Old 08-07-2013, 08:46 PM   #3
steak1987
Member
 
Registered: Jan 2012
Posts: 130

Original Poster
Rep: Reputation: Disabled
I was actually thinking of that. Could it be possible to have a small script in the background saving the output of the uptime command as well as another command showing battery life ?

Maybe having the output saved to a txt file.


However, there is one issue that comes to mind. Im running on solid state memory, and im worried about what will happen if I were to be writing the data onto the disk as the power fails ? I would risk memory corruption, wouldnt I ?


In that case, is there any way to make a script that logs the battery percentate and the uptime (or script start time), till maybe 5% battery capacity, at which point it stops recording ?


Looking around google, Ive seen the ibam package is pretty helpful:

http://www.brighthub.com/computing/l...les/13876.aspx

Code:
$ ibam --percentbattery
Battery percentage:         90 %
Battery time left:           1:51:46
Adapted battery time left:   1:57:18

_________________________________________________________________________________________

EDIT:

Ive kinda answered parts of my own question thanks to google.

Code:
$ ibam --percentbattery; uptime >> /home/XXXX/batteryt3.txt
This is a script that is supposed to write the uptime and battery percentage onto a file.

However, the file is a bit glitched. The output file is only the uptime and the load.

How would I save both commands to a text file, similar to the output when displaying it in terminal?

Code:
$ ibam --percentbattery; uptime
Battery percentage:         83 %
Battery time left:           2:14:16
Adapted battery time left:   2:55:00
 11:58:06 up 30 min,  2 users,  load average: 0.06, 0.45, 0.52
Also, how would I schedule this to run every 60 seconds ?

Is there any way to stop recording when the battery percentage runs below a certain amount ?

Thanks for your advise...

Last edited by steak1987; 08-07-2013 at 09:01 PM.
 
Old 08-08-2013, 04:39 PM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by steak1987 View Post

Also, how would I schedule this to run every 60 seconds ?

Is there any way to stop recording when the battery percentage runs below a certain amount ?

Thanks for your advise...
Hey! Sorry to be so long responding, have been away the past couple of days.

As for your question quoted here, see man cron, but here is a quick answer:

1. Create a shell script that captures and records the battery data you want to keep, let's call it batterycapture.sh
2. Make sure the script is executable, like this: chmod +x batterycapture.sh (and test it to be sure it does what you want!)
2. Set up a line in your crontab that runs this script every minute of every day using crontab -e, like this...

Code:
crontab -e

... then enter...

* * * * * path_to_script/batterycapture.sh
It will then run your script every minute of every day of every week of every month.

To turn it off simply remove or comment out the line in your crontab.

I'll follow shortly with another post about how I do it with MySQL.

Last edited by astrogeek; 08-08-2013 at 04:41 PM.
 
1 members found this post helpful.
Old 08-08-2013, 05:10 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Here is how I do it using MySQL database - please consider this a guide, not a detailed how-to.

You will need a MySQL instance running, should be there in any Linux, be sure the service is running.

You will need to create a user account and DB, see your distro's docs or try this from mysql client:

Code:
CREATE DATABASE battery;

GRANT ALL ON battery.* TO your_user@localhost IDENTIFIED BY 'your_pass';
Once you have a database and user account, create the table to use to capture the raw data...

Code:
CREATE TABLE `battery` (
    `id` INTEGER NOT NULL AUTO_INCREMENT COMMENT 'Record unique id',
    `ts` INTEGER NOT NULL COMMENT 'Unix timestamp',
    `batt` VARCHAR(12) NOT NULL COMMENT 'Battery installed',
    `capState` VARCHAR(16) NOT NULL COMMENT 'Capacity state',
    `chgState` VARCHAR(16) NOT NULL COMMENT 'Charge state',
    `rate` MEDIUMINT NOT NULL COMMENT 'Chg/dischg rate mAh',
    `remaining` MEDIUMINT NOT NULL COMMENT 'remaining mAh',
    `mv` MEDIUMINT NOT NULL COMMENT 'Voltage in mv',
    CONSTRAINT `PK_battery` PRIMARY KEY (`id`)
) COMMENT = 'Battery data';
Next, create the capture script using your editor of choice, fill in the user and pass with your own...

Code:
#!/bin/sh

present=`cat /proc/acpi/battery/BAT1/state |grep 'present:' | sed s/^.*:[^a-z0-9]*//g`
capacity_state=`cat /proc/acpi/battery/BAT1/state |grep 'capacity state' | sed s/^.*:[^a-z0-9]*//g`
charging_state=`cat /proc/acpi/battery/BAT1/state |grep 'charging state' | sed s/^.*:[^a-z0-9]*//g`
present_rate=`cat /proc/acpi/battery/BAT1/state |grep 'present rate' | sed s/[^0-9]*//g`
remaining=`cat /proc/acpi/battery/BAT1/state |grep 'remaining' | sed s/[^0-9]*//g`
present_volt=`cat /proc/acpi/battery/BAT1/state |grep 'present volt' | sed s/[^0-9]*//g`
#Now write the query...
SQL="INSERT INTO battery SET id=NULL, ts=UNIX_TIMESTAMP(), batt='${present}', capState='${capacity_state}', chgState='${charging_state}', rate='${present_rate}', remaining='${remaining}', mv='${present_volt}' "

if [ "$1" ]; then
echo $present
echo $capacity_state
echo $charging_state
echo $present_rate
echo $remaining
echo $present_volt
echo "$SQL"
fi


mysql -u your_user -pyour_pass battery -e "$SQL"
To test it, make it executable and simply run it, then check the database to see if a record was created...

Code:
chmod +x batterycapture.sh

./batterycapture.sh

mysql -pyour_pass battery -e 'SELECT * FROM battery'
Finally, add to your crontab...

Code:
crontab -e

* * * * * path_to_script/batterycapture.sh
You should then be collecting raw batter data, something like this...

Code:
mysql [test]> select * from battery order by id limit 10;
+----+------------+------+----------+----------+------+-----------+-------+
| id | ts         | batt | capState | chgState | rate | remaining | mv    |
+----+------------+------+----------+----------+------+-----------+-------+
|  7 | 1375568382 | yes  | ok       | charging |  271 |      2408 | 15000 |
|  8 | 1375568461 | yes  | ok       | charging |  261 |      2408 | 15000 |
|  9 | 1375568521 | yes  | ok       | charging |  255 |      2434 | 15000 |
| 10 | 1375568581 | yes  | ok       | charging |  249 |      2434 | 15000 |
| 11 | 1375568641 | yes  | ok       | charging |  243 |      2434 | 15000 |
| 12 | 1375568701 | yes  | ok       | charging |  238 |      2434 | 15000 |
| 13 | 1375568761 | yes  | ok       | charging |  232 |      2434 | 15000 |
| 14 | 1375568821 | yes  | ok       | charging |  227 |      2434 | 15000 |
| 15 | 1375568881 | yes  | ok       | charging |  222 |      2459 | 15000 |
| 16 | 1375568941 | yes  | ok       | charging |  216 |      2459 | 15000 |
+----+------------+------+----------+----------+------+-----------+-------+
At this point you will be collecting raw battery data and can query it any way that you like.

You may want to see other things as you indicated in your earlier posts, so you will need to modify the table structure to store them and modify the script to capture them, but let's consider that beyond the scope of this particular post and focus on getting the database working and make sure the basic data I capture is available on your system.

One additional point - if you leave the cron running forever you will get 1440 new data points in the DB every day. That is not a problem, but might not be really necessary. For my own use I enable the cron then pull the power cord and let the battery power my laptop until it is nearly depleted during normal use. I then repeat for the recharge cycle, and disable the cron afterward. That gives me single complete data set.

I hope this is not too cryptic and is helpful to you!

Last edited by astrogeek; 08-08-2013 at 05:11 PM.
 
Old 08-11-2013, 07:59 AM   #6
steak1987
Member
 
Registered: Jan 2012
Posts: 130

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
Hey! Sorry to be so long responding, have been away the past couple of days.

As for your question quoted here, see man cron, but here is a quick answer:

1. Create a shell script that captures and records the battery data you want to keep, let's call it batterycapture.sh
2. Make sure the script is executable, like this: chmod +x batterycapture.sh (and test it to be sure it does what you want!)
2. Set up a line in your crontab that runs this script every minute of every day using crontab -e, like this...

Code:
crontab -e

... then enter...

* * * * * path_to_script/batterycapture.sh
It will then run your script every minute of every day of every week of every month.

To turn it off simply remove or comment out the line in your crontab.

I'll follow shortly with another post about how I do it with MySQL.
I really have very little experience with MySQL so ill probably use the script+crontab method.

I want to write the output of two different commands to the same text file, after each other.
I tried using google and came up with a way to display all the information in the terminal window:

Code:
$ ibam --percentbattery; uptime
Battery percentage:         83 %
Battery time left:           2:14:16
Adapted battery time left:   2:55:00
 11:58:06 up 30 min,  2 users,  load average: 0.06, 0.45, 0.52
The question now is, how would I save the output to a text file ? I tried this command:

Code:
$ ibam --percentbattery; uptime >> /home/XXXX/batteryt3.txt
however, only the uptime and the load is recorded, not the battery statistics.
 
Old 08-11-2013, 02:11 PM   #7
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by steak1987 View Post
I really have very little experience with MySQL so ill probably use the script+crontab method.
That is understandable, I did not mean to push it on you, but offered as "the way I do it".

Quote:
Originally Posted by steak1987 View Post
I want to write the output of two different commands to the same text file, after each other.
I tried using google and came up with a way to display all the information in the terminal window:
...
The question now is, how would I save the output to a text file ? I tried this command:

Code:
$ ibam --percentbattery; uptime >> /home/XXXX/batteryt3.txt
however, only the uptime and the load is recorded, not the battery statistics.
Yea, only the second is going to the file. You could do it all on one line, but if you are adding it to the cron anyway, it is probably better to put it into a file.

I would put the following in a file, call it cronbatt.sh, then add that file to your crontab:

Code:
#!/bin/sh

ibam --percentbattery >> /path_to/data_file
uptime >> /path_to/data_file

#Enable the following line to add a blank line between records
echo " " >>/path_to/data_file
Then

Code:
chmod +x cronbatt.sh
Then add to your crontab...

Code:
* * * * * /path_to/cronbatt.sh
In both the cronbatt.sh script and the crontab line, the paths need to be full path from /, so I have shown the leading slash to emphasize that.

Hope this helps!

Last edited by astrogeek; 08-11-2013 at 03:03 PM. Reason: typos
 
1 members found this post helpful.
Old 08-13-2013, 10:50 PM   #8
steak1987
Member
 
Registered: Jan 2012
Posts: 130

Original Poster
Rep: Reputation: Disabled
Question

I made some minor modifications:

Code:
#!/bin/sh

ibam --percentbattery >> /home/XXXX/Scripts/battcron/cronbatt.txt
date >> /home/XXXX/Scripts/battcron/cronbatt.txt
uptime >> /home/XXXX/Scripts/battcron/cronbatt.txt

#Enable the following line to add a blank line between records
echo " " >>/home/XXXX/Scripts/battcron/cronbatt.txt
as for the crontab file:

Code:
  GNU nano 2.2.6        File: /tmp/crontab.eqsEAF/crontab                       

# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
* * * * * /home/XXXX/Scripts/battcron/cronbatt.sh
Works beautifully.

One last question though, in order to prevent damage with the battery failing as the battery file is being written, I want to have the computer go through a "tidy" shutdown when the battery is at a really low percent, like 5-7%.

http://i.imgur.com/QwnTZYs.png

I assume I need to run the "init 0" or the "shutdown -h" command but both need root access, and I wont be there to add the password.


I assume this guide should be sufficient:

http://superuser.com/questions/44036...xecute-as-root

But, I'm worried about modifying access rights to folders in my home folder. Any tips ? Can I just modify the access rights to the file without touching the folder rights ?
 
Old 08-13-2013, 11:08 PM   #9
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Hey! Very good!

Not sure where you are saying you want to put the shutdown command.

I do not recognize the dialog in the image you attached, but if it is a system configuration dialog then it should have the necessary rights to run init 0 or shutdown. If it is a KDE or Gnome desktop dialog then maybe or maybe not. The best I can do for those is tell you to see the available docs as I do not use either.

On the other hand, if you want to detect the level and do the shutdown from the cron script, then I would suggest moving the script to a root owned location, maybe /sbin or somewhere in /root/... and add it to the root crontab instead of the normal user - then permissions are not a problem.

You could change ownership of just the cronbatt.sh script to root, but if it is running from your user crontab it will still be running with your user permission, not root.
 
Old 08-15-2013, 03:00 AM   #10
steak1987
Member
 
Registered: Jan 2012
Posts: 130

Original Poster
Rep: Reputation: Disabled
The application is xfce-battery

http://goodies.xfce.org/projects/pan...battery-plugin

I assume the command is run as the current user ? I did a bit of googling and came up with this, posted in 2006:

http://forum.xfce.org/viewtopic.php?id=2766

Would that be relevant ?

Quote:
Originally Posted by stonecrest
Yes, you'll need to use sudo and make sure that you're allowed to run the command without a password.
/etc/sudoers
Code:
username ALL=NOPASSWD:/sbin/shutdown -h now

Should I leave username unchanged or use my own ?


EDIT: also, can I use "gksu gedit" as opposed to visudo ?

Last edited by steak1987; 08-15-2013 at 03:05 AM.
 
Old 08-15-2013, 03:17 AM   #11
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by steak1987 View Post
The application is xfce-battery

http://goodies.xfce.org/projects/pan...battery-plugin

I assume the command is run as the current user ? I did a bit of googling and came up with this, posted in 2006:

http://forum.xfce.org/viewtopic.php?id=2766

Would that be relevant ?
Yea, that probably runs as the login user, and yes, that forum thread looks like exactly what you need!

Quote:
Originally Posted by steak1987 View Post
Should I leave username unchanged or use my own ?


EDIT: also, can I use "gksu gedit" as opposed to visudo ?
Use your own user name in that line and add it to /etc/sudoers.

Not sure about gksu as I do not have it on Slackware (my distro of choice). Looking online it looks like a user front end to sudo, not a replacement for visudo. On the other hand, if it will allow you to edit /etc/sudoers then it will work. If not, just open a terminal, be root and visudo.

I think that will get you going.

Last edited by astrogeek; 08-15-2013 at 03:20 AM.
 
Old 08-15-2013, 06:56 AM   #12
steak1987
Member
 
Registered: Jan 2012
Posts: 130

Original Poster
Rep: Reputation: Disabled
Ooookay, I thought it was smooth sailing, apparently not.

Code:
#includedir /etc/sudoers.d

#username ALL=NOPASSWD:/sbin/shutdown -h now

XXXX ALL=NOPASSWD:/sbin/shutdown -h now
Unfortunately it doesnt seem to work, but this may be with the battery monitor widget than sudoers.

Alright, new option maybe ? Something possibly more robust ?


http://askubuntu.com/questions/69556...using-terminal

Using that, I figured out how to use grep (YAY!), and the command I am supposed to do is:

Code:
upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -E "state|to\ full|percentage"
    state:               charging
    time to full:        51.3 minutes
    percentage:          28.0971%

My idea is to make a script using that command, and run a cron job every minute, to see if the battery percentage drops below 5% (without a charger present), then to initiate shutdown.

so, I made the bash script, and chmoded it:

Code:
XXXX@XXXX-Latitude-D430 ~/Scripts/battshutdown $ sudo chmod +x battshutdown.sh 
[sudo] password for XXXX: 
XXXX@XXXX-Latitude-D430 ~/Scripts/battshutdown $ ./ battshutdown.sh 
bash: ./: Is a directory
XXXX@XXXX-Latitude-D430 ~/Scripts/battshutdown $ ./battshutdown.sh 
    state:               charging
    time to full:        51.6 minutes
    percentage:          35.8538%
XXXX@XXXX-Latitude-D430 ~/Scripts/battshutdown $ cat battshutdown.sh 
#!/bin/sh

upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -E "state|to\ full|percentage"
So far, its all been relatively simple, but how would I get a script to read the output of that command, and if the value of "percentage" is less than 5, and the "state" is discharging, then run a shutdown script (sudo init 0) ?


Apologies if the answer seems pretty obvious, I cant seem to figure out what to do.
 
Old 08-16-2013, 01:33 AM   #13
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by steak1987 View Post
Ooookay, I thought it was smooth sailing, apparently not.

Code:
#includedir /etc/sudoers.d

#username ALL=NOPASSWD:/sbin/shutdown -h now

XXXX ALL=NOPASSWD:/sbin/shutdown -h now
Unfortunately it doesnt seem to work, but this may be with the battery monitor widget than sudoers.
Actually, that should work as long as the battery monitor thingy actually runs as your user name.

Looking back at the referenced thread, there is apparently a selection for "Run in terminal" or "Run command" (I forget exact wording). Be sure to select NOT run in terminal from that applet.

Using the applet would make the shutdown independent of whether your script was running - probably a good thing, so I'd check that first.

Quote:
Originally Posted by steak1987 View Post
Alright, new option maybe ? Something possibly more robust ?


http://askubuntu.com/questions/69556...using-terminal

Using that, I figured out how to use grep (YAY!), and the command I am supposed to do is:

Code:
upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -E "state|to\ full|percentage"
    state:               charging
    time to full:        51.3 minutes
    percentage:          28.0971%

My idea is to make a script using that command, and run a cron job every minute, to see if the battery percentage drops below 5% (without a charger present), then to initiate shutdown.


[SNIP]

So far, its all been relatively simple, but how would I get a script to read the output of that command, and if the value of "percentage" is less than 5, and the "state" is discharging, then run a shutdown script (sudo init 0) ?


Apologies if the answer seems pretty obvious, I cant seem to figure out what to do.
You could do that. But since your battery log cron is already running every minute, why not just include it in there.

Something like this should do it, and write the shutdown to the log in the process...

Code:
...
## Add to bottom of your cronbatt.sh
PCT=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -E "percentage" | sed 's/^[^0-9]*\([0-9]*\).*/\1/')
if [ "$PCT" ] && [ "$PCT" -le "5" ]; then
        echo "SHUTTING DOWN AT ${PCT}%" >> /home/XXXX/Scripts/battcron/cronbatt.txt
        shutdown -h now
fi
You could of course run that as a separate cron, but if your cronbatt.sh is always running anyway, why not combine them?

Note that I tested the sed expression on a string, but I do not have upower on my system either, so be sure to test it before letting it run free! Maybe disable the shutdown line and echo the output manually to be sure it works with the upower output.

Hope this helps! Let me know!

[EDIT]
Just realized this does not check for charger present, but in practice that should not be a problem. If it is required we can add detection for that too, but out of time for now.
[/EDIT]

Last edited by astrogeek; 08-16-2013 at 01:42 AM.
 
1 members found this post helpful.
Old 08-17-2013, 02:59 AM   #14
steak1987
Member
 
Registered: Jan 2012
Posts: 130

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
Actually, that should work as long as the battery monitor thingy actually runs as your user name.

Looking back at the referenced thread, there is apparently a selection for "Run in terminal" or "Run command" (I forget exact wording). Be sure to select NOT run in terminal from that applet.


Using the applet would make the shutdown independent of whether your script was running - probably a good thing, so I'd check that first.



You could do that. But since your battery log cron is already running every minute, why not just include it in there.

Something like this should do it, and write the shutdown to the log in the process...

Code:
...
## Add to bottom of your cronbatt.sh
PCT=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -E "percentage" | sed 's/^[^0-9]*\([0-9]*\).*/\1/')
if [ "$PCT" ] && [ "$PCT" -le "5" ]; then
        echo "SHUTTING DOWN AT ${PCT}%" >> /home/XXXX/Scripts/battcron/cronbatt.txt
        shutdown -h now
fi
You could of course run that as a separate cron, but if your cronbatt.sh is always running anyway, why not combine them?

Note that I tested the sed expression on a string, but I do not have upower on my system either, so be sure to test it before letting it run free! Maybe disable the shutdown line and echo the output manually to be sure it works with the upower output.

Hope this helps! Let me know!

[EDIT]
Just realized this does not check for charger present, but in practice that should not be a problem. If it is required we can add detection for that too, but out of time for now.
[/EDIT]

I tried both options, the first one didnt work, when I selected "run in terminal window", a terminal popup appeared, waiting for a password (I couldnt get to it in time, the battery died).


EDIT: Waiting to see if your script works, had some issues, will update this thread either way
 
Old 08-17-2013, 03:18 AM   #15
steak1987
Member
 
Registered: Jan 2012
Posts: 130

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
You could do that. But since your battery log cron is already running every minute, why not just include it in there.

Something like this should do it, and write the shutdown to the log in the process...

Code:
...
## Add to bottom of your cronbatt.sh
PCT=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -E "percentage" | sed 's/^[^0-9]*\([0-9]*\).*/\1/')
if [ "$PCT" ] && [ "$PCT" -le "5" ]; then
        echo "SHUTTING DOWN AT ${PCT}%" >> /home/XXXX/Scripts/battcron/cronbatt.txt
        shutdown -h now
fi
You could of course run that as a separate cron, but if your cronbatt.sh is always running anyway, why not combine them?

Note that I tested the sed expression on a string, but I do not have upower on my system either, so be sure to test it before letting it run free! Maybe disable the shutdown line and echo the output manually to be sure it works with the upower output.

Hope this helps! Let me know!

[EDIT]
Just realized this does not check for charger present, but in practice that should not be a problem. If it is required we can add detection for that too, but out of time for now.
[/EDIT]


I tried running that as a cron job, no luck. I let the battery run down to about 3% (monitored by the following command:

Code:
$ upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -E "percentage"
    percentage:          8.45424%
but still, the computer didnt initiate shut down.
 
  


Reply

Tags
battery, benchmark, benchmarking



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
Benchmark program for Linux? Larry James Linux - General 3 12-04-2008 10:04 AM
battery life benchmark on gnome vs kde paulsiu Linux - Laptop and Netbook 1 05-08-2008 10:46 AM
3D Benchmark in Linux ? houmie SUSE / openSUSE 4 04-06-2005 12:46 PM
All Around Linux Benchmark TuxFreak Linux - Software 2 11-25-2004 05:40 PM
Benchmark linux p4 vs mac 9 or 10 iwkua Linux - General 3 02-22-2004 07:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Laptop and Netbook

All times are GMT -5. The time now is 09:48 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