dmesg reads the Kernel log ring buffer. It doesn't do timestamps. What you should do is configure syslog to grab the kernel logs from that buffer and send them to a file (if it isn't already set to do so). Note, default CentOS 5.x syslog config sends kernel logs to /var/log/messages, as I recall.
If you'd like to send all kernel (dmesg) logs to /var/log/kern.log, using the default syslog daemon, you'd add a line like the following to /etc/syslog.conf
I've written this simple script. Yes, it's slow. If you want something faster you either actually write a script on perl, python or something else. I'm sure this simple script can give you the hang of how it can be calculated.
Please note I ignored the seconds fraction registered in each line (after the . in the timestamp).
perl -n is a way to read standard input and read into variable $_.
The body (not the BEGIN section) is then run once for each line.
BEGIN runs the code in {} once.
$a is the start of dmesg since the epoch
The s/... command takes the value in $_ and substitutes the #####.###### part of the timestamp with the "localtime" version of the dmesg offset ( $1) added to the system start time ($a)
print $a prints the dmesg with the locale friendly time stamp substituted for the "seconds since boot" time stamp.
perl -n is a way to read standard input and read into variable $_.
The body (not the BEGIN section) is then run once for each line.
BEGIN runs the code in {} once.
$a is the start of dmesg since the epoch (seconds)
The s/... command takes the value in $_ and substitutes the \s*#####.###### part of the timestamp with the "localtime" version of the dmesg offset ( $1) added to the system start time ($a)
print $a prints the dmesg with the locale friendly time stamp substituted for the "seconds since boot" time stamp.
dmesg
reads the Kernel log ring buffer. It doesn't do timestamps. What you should do is configure syslog to grab the kernel logs from that buffer and send them to a file (if it isn't already set to do so). Note, default CentOS 5.x syslog config sends kernel logs to/var/log/messages
, as I recall.If you'd like to send all kernel (dmesg) logs to
/var/log/kern.log
, using the default syslog daemon, you'd add a line like the following to/etc/syslog.conf
There is solution "Enabling Timestamps for dmesg/Kernel Ring Buffer"
You could add:
to kernel cmdline.
As for me, I have added to rc.local on all machines with puppet. It's easier for me) :
I've written this simple script. Yes, it's slow. If you want something faster you either actually write a script on perl, python or something else. I'm sure this simple script can give you the hang of how it can be calculated.
Please note I ignored the seconds fraction registered in each line (after the . in the timestamp).
I hope it helps. :)
A little perl script as below. It's a general way, and I'm not the author.
perl -n
is a way to read standard input and read into variable $_.Script modification in case line do not begin with a "["
This is an update on Plutoid's suggestion, removing the leading spaces from the timestamp.