How to convert 'dmesg' time format to 'real' time format
Solution 1:
It looks as if it was implemented recently for Quantal (12.10) : see http://brainstorm.ubuntu.com/idea/17829/ .
Basically, dmesg
is reported to have a new switch -T, --ctime
.
Edit. As another extension on Ignacio's answer, here are some scripts to enhance dmesg output on older systems.
( Note: for the python version of the code shown there, one will want to replace <
and >
back to <>
to make it usable again. )
Finally, for a single value like 600711.395348
one could do
ut=`cut -d' ' -f1 </proc/uptime`
ts=`date +%s`
date -d"70-1-1 + $ts sec - $ut sec + 600711.395348 sec" +"%F %T"
and get the event date and time.
( Please note that due to round-off errors the last second digit probably won't be accurate. ) .
Edit(2): Please note that -- as per Womble's comment below, -- this will only work if the machine was not hibernated etc. ( In that case, one shall better look at syslog
configs at /etc/*syslog*
and check the appropriate files. See also: dmesg vs /var/messages . )
Solution 2:
To extend on Ignacio's answer, the entries contained in dmesg
are typically also logged elsewhere on the system, via syslog, which will give you a "real" timestamp. Unless Ubuntu have changed the Debian-set default, the log entries should be in /var/log/kern.log
.
Solution 3:
The time given in dmesg is in seconds since kernel startup. So, just add that many seconds to when the kernel started running (hint: uptime).
Solution 4:
I know this is now old but dmesg now has a built in -e or --reatime option to display the time in the local time.
root@bbs:/var/log# dmesg|tail -1
[50755952.379177] Out of memory in UB 1593: OOM killed process 3183 (sbbs) score 0 vm:747204kB, rss:242764kB, swap:88224kB
root@bbs:/var/log# dmesg -e|tail -1
[Feb20 17:10] Out of memory in UB 1593: OOM killed process 3183 (sbbs) score 0 vm:747204kB, rss:242764kB, swap:88224kB
Solution 5:
On busybox, the 3 liner above didn't work, so here is my way to calculate it one off (replace 1628880.0
with your dmesg
timestamp):
perl -e '@a=split(`/proc/uptime`);print scalar(localtime(time()+$a[0] - 1628880.0)."\n");'