This is a shell script I wrote on and for a very old laptop (old as in it had a P1 processor) I had. I got the laptop and had heard that the battery was in a bad condition, but after using it for a bit I thought it wasn’t that shabby. To put it to the test I had two choices. Sit by the computer and time it, or write a shell script to log the battery level as it went. I obviously went with the shell script.
It has two modes, analyze mode and log mode. They’re called with ‘utp -a FILE’ and ‘utp -l FILE’ respectively. The log mode writes the time and the battery level, separated by a comma, to the specified file, sleeps for a second, and repeats. Here is more exactly what it writes:
echo "$(date +%T), $(apm | cut -d' ' -f5)" | tee -a $OPTARG
The analyze mode echoes the percent in tens (100-91%, 90-81% etc) and how long those percent took and finally a summary, from what percent it started from to at what percent the last logging took place and how long the whole thing took. Here is an example output (with a faked file so it doesn’t make much sense):
Percent: Time: 100 - 91: 0m10s 90 - 81: 0m10s 80 - 71: 0m10s 70 - 61: 0m10s 60 - 51: 0m10s 50 - 41: 0m10s 40 - 31: 0m10s 30 - 21: 0m10s 20 - 11: 0m10s 10 - 01: 0m10s The script was logging from 100% to 1% in 1 minutes.
It’s free as in free speech (and free beer) so you have no restrictions regarding usage or modifications to it, but it’s always nice to hear from anyone using what you make so feel free to post a comment or send me a mail. Any bug fixes, improvements or other additions would be neat to get so I can host the new version here. :)