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?

  • I don't have a laptop, but try cat /var/log/syslog | grep -i battery and see. –  Oct 04 '16 at 09: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 04 '16 at 10:39
  • Maybe here you'll find a clue for the ouput you want: http://askubuntu.com/questions/69556/how-to-check-battery-status-using-terminal – gl00ten Oct 05 '16 at 15:00

1 Answers1

9

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
lemonsqueeze
  • 1,634