Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have (for example) this log entry in dmesg output:

[600711.395348] do_trap: 6 callbacks suppressed

Is there a possibility to convert this 'dmesg' time to 'real' time to know, when this event happend?

share|improve this question
up vote 29 down vote accepted

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 &lt; and &gt; 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. ) .

share|improve this answer
1  
And, as an added bonus, if the machine's ever been suspended, you're completely doomed, because the time spent asleep isn't accounted for. – womble Sep 2 '15 at 23:28

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.

share|improve this answer
    
Thanks for a note... – Jan Marek Mar 5 '12 at 8:59
    
On Cent OS 5 and 6, the log entry is in /var/log/messages. – emerino Nov 25 '15 at 19:07

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).

share|improve this answer
1  
Thanks a lot... – Jan Marek Mar 5 '12 at 8:58

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");'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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