Like most users that have searched know, Manufacturers ACPI implementation is a mess and for most of our laptops, battery info is unavailable or wrong (on a dell inspiron 15z, the rate is divided by 10).

Is there a way (using a perl/python/bash script, an existing package or whatever) to log battery cycles on Ubuntu 12.04?

(what is a battery cycle ?)

A charge cycle means using all of the battery’s power, but that doesn’t necessarily mean a single charge. For instance, you could listen to your [device] for a few hours one day, using half its power, and then recharge it fully. If you did the same thing the next day, it would count as one charge cycle, not two, so you may take several days to complete a cycle. Each time you complete a charge cycle, it diminishes battery capacity slightly, but you can put [device battery] through many charge cycles before they will only hold 80% of original battery capacity. Apple courtesy

My laptop is a Clevo W150HRM, and when I do : cat /sys/class/power_supply/BAT0/cycle_count I get: 0 My laptop is 2 years old.

Thank you by advance.

  • counters are not hard. what data can you use to count?
    – grantbow
    Apr 24, 2015 at 13:09
  • Of course counters are hard ! They're stored on the battery firmware. (Yes, batteries DO have firmwares)
    – Bahaïka
    Jun 11, 2015 at 23:15

1 Answer 1


I've just looked into your question... so it might be too late to answer you since it's been years you've posted it.

You are using a rather old ubuntu that is known/was known at that time to have trouble in that specific domain.

However I encourage you to see this question : How to check battery status using terminal?

The answer of Lekensteyn is the start of what you are looking for.

As you can see in the answer the matter evolves along the kernel version and so the solution ...

To be more specific and retaking your conditions (get status and ubuntu 12.04), you need upower in your system and can create a script like :

DATE=$(date +%Y-%m-%d:%H:%M:%S)
STATE=$(upower -i /sys/class/power_supply/BAT0 | awk '/state/ {print $2}')
echo "$DATE $STATE" >> /var/log/battery_status.log

Then add it in a monitoring process loop ... or a crontab.

It might need root privilege (sudo)

Hope this helps.

  • I tried, the $STATE returns blank. even just running the line separately. What is missing? ys GCP
    – GCP420
    Aug 6, 2018 at 15:49
  • You can run upower -d to dump all data and see what your device is (mine is called /org/freedesktop/UPower/devices/battery_BAT0). upower -h provides more help. Here's a script that stores the date and eight relevant numbers to a log file for my situation: gist.github.com/AstroFloyd/456f7db5ec80409d617211ce1579c2b4
    – AstroFloyd
    Jan 16 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.