10

I am looking for log entries of when my device is plugged and unplugged to/from mains power, or when the battery changes from discharging/charging state. Which log entries do I need to look for for this?

3
  • I don't have a laptop, but try cat /var/log/syslog | grep -i battery and see. – user423626 Oct 4 '16 at 9:48
  • Thanks for the suggestion, I have already tried sudo grep -i battery /var/log/* but nothing pertaining to charging is found. – Holy Mackerel Oct 4 '16 at 10:39
  • Maybe here you'll find a clue for the ouput you want: askubuntu.com/questions/69556/… – fullmooninu Oct 5 '16 at 15:00
7

See this question:

UPower stores its historical information in four files in /var/lib/upower/
This is the data gnome-power-statistics uses to draw its charge/discharge profiles.
For example:

$ ls -t /var/lib/upower/* | head -4
/var/lib/upower/history-time-empty-AL15B33-48-3241.dat
/var/lib/upower/history-time-full-AL15B33-48-3241.dat
/var/lib/upower/history-charge-AL15B33-48-3241.dat
/var/lib/upower/history-rate-AL15B33-48-3241.dat

Looks like you could check charging/discharging state changes in the history-charge file:

$ cat history-charge-AL15B33-48-3241.dat
1475784954      58.000  discharging
1475785164      57.000  discharging
1475785344      56.000  discharging
1475785598      57.000  charging
1475786432      58.000  charging

Fist column is timestamp. You could use date -s @timestamp to get something more readable:

$ cat history-charge-AL15B35-48-3241.dat | while read f; do
  d=$(date +"%b %e %H:%M:%S" -s @`echo $f | cut -d\  -f1`);
  echo "$d  $f" ; done
Oct  6 22:15:54  1475784954      58.000  discharging
Oct  6 22:19:24  1475785164      57.000  discharging
Oct  6 22:22:24  1475785344      56.000  discharging
Oct  6 22:26:38  1475785598      57.000  charging
Oct  6 22:40:32  1475786432      58.000  charging
2
  • Awesome just what I was after. I knew the data had to exist somewhere! Thank you. – Holy Mackerel Oct 8 '16 at 2:19
  • 2
    small correction: date -d not -s – Julien Carsique Nov 22 '18 at 17:43

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.