Dmesg with date possible?

Hi there,

I miss date information when executing # dmesg

Is it possible to add this a date information to my results of # dmesg
?

Best wishes

Did you try dmesg -T ?

---------- Post updated at 08:25 PM ---------- Previous update was at 08:24 PM ----------

$ dmesg --v
dmesg from util-linux 2.20.1

dmesg -T is not available von HP Unix
man dmesg is also not helpful

Unixsystem is version 11.31

Okay, try this perl script, not written by me, but this might help you

$ cat time.pl 
#!/usr/bin/perl -wn
use strict;
 
foreach my $line (<>) {
    my ($uptime) = do { local @ARGV='/proc/uptime';<>}; ($uptime) = ($uptime =~ /^(\d+)\./);
    $line=~/^\[\s*(\d+)\.\d+\](.+)/;
    printf "[%s]%s\n", scalar localtime(time - $uptime + $1), $2;
}

usage :

$ dmesg | perl time.pl

Normally its the first thing written by dmesg...
typing just dmesg |more produces (sorry no HPUX11.31...):

Mar 17 15:59
gate64: sysvec_vaddr = 0xc0002000 for 2 pages
NOTICE: autofs_link(): File system was registered at index 3.
. etc

That didn't work ;(

# dmesg | perl time.pl | more
syntax error at time.pl line 1, near "$ cat time"
"use" not allowed in expression at time.pl line 3, at end of line
Execution of time.pl aborted due to compilation errors.

I tried this one:

#!/usr/bin/perl -wn
use strict;
foreach my $line (<>) {
    my ($uptime) = do { local @ARGV='/proc/uptime';<>}; ($uptime) = ($uptime =~ /^(\d+)\./);
    $line=~/^\[\s*(\d+)\.\d+\](.+)/;
    printf "[%s]%s\n", scalar localtime(time - $uptime + $1), $2;
}

But it's also not working ;(

Can't open /proc/uptime: No such file or directory at time.pl line 5.
Use of uninitialized value in pattern match (m//) at time.pl line 5.
Use of uninitialized value in subtraction (-) at time.pl line 7.
Use of uninitialized value in addition (+) at time.pl line 7.
Use of uninitialized value in printf at time.pl line 7.
dmesg | more

... doesn't show date - just on the top I could see the actual date ;-(

If dmesg doesn't show date, how could something else going to add date?

Exactly the only date you will get is that of dmesg execution... look at the man pages!

I wonder if you are not confusing with what you see in syslog.log file...

@Corona688 I don't know much about it, its looks like dmesg output is in nanoseconds from this article How to enable time stamps for logs in 'dmesg' on Gaia OS and SecurePlatform OS, I didn't go much into it since my system supports -T option.

Good point. Right now that's a mystery. If the OP could post some output, that would be nice. If it doesn't have timestamps already, we can't really add them.

Yes, thats true.

Now there are no new messages shown. Here's an example.

# dmesg
0/0/0/10/0/0/1.0x5006016930201d6b.0x400d000000000000 eslpt
0/0/0/10/0/0/0.0x5006016930201d6b.0x400e000000000000 eslpt
0/0/0/10/0/0/1.0x5006016930201d6b.0x400e000000000000 eslpt
0/0/0/10/0/0/0.0x5006016930201d6b.0x4014000000000000 eslpt
0/0/0/10/0/0/1.0x5006016930201d6b.0x4014000000000000 eslpt
0/0/0/10/0/0/0.1.3.255.0 fcd_vbus
0/0/0/10/0/0/0.1.3.253.0.0 tgt
0/0/0/10/0/0/1.2.3.255.0 fcd_vbus
0/0/0/10/0/0/0.1.3.253.0.0.0 sctl
0/0/0/10/0/0/1.2.3.253.0.0 tgt
0/0/0/10/0/0/1.2.3.253.0.0.0 sctl
0/0/0/10/0/0/0.1.3.0.0 fcd_vbus
0/0/0/10/0/0/0.1.3.0.0.0 tgt
0/0/0/10/0/0/0.1.3.0.0.0.1 sdisk
0/0/0/10/0/0/1.2.3.0.0 fcd_vbus
0/0/0/10/0/0/1.2.3.0.0.0 tgt
0/0/0/10/0/0/1.2.3.0.0.0.1 sdisk
0/0/0/10/0/0/0.1.3.0.0.0.2 sdisk

There's no need to have a date here but sometimes we have problems after one or two weeks so it would be very helpful to have a date in this situation.

;-(

a thought - why not clear the messages everyday after storing it into a log file with current date? a cron should do.

---------- Post updated at 11:53 PM ---------- Previous update was at 11:48 PM ----------

I just noticed the logs are already rotated. Not sure if your system does it. Check these files

root@maximus:/tmp# ls -lrt /var/log/dmes*
-rw-r----- 1 root adm     28 Jan  8 09:39 /var/log/dmesg.4.gz
-rw-r----- 1 root adm  13463 Feb 17 00:53 /var/log/dmesg.3.gz
-rw-r----- 1 root adm  13376 Feb 17 19:41 /var/log/dmesg.2.gz
-rw-r----- 1 root adm  13544 Feb 19 19:57 /var/log/dmesg.1.gz
-rw-r----- 1 root adm  49431 Feb 23 12:36 /var/log/dmesg.0
-rw-r----- 1 root adm  49773 Mar  2 16:27 /var/log/dmesg

On a second thought I guess these are created either when the system boots up or shuts down.

---------- Post updated 03-19-14 at 12:00 AM ---------- Previous update was 03-18-14 at 11:53 PM ----------

Script log_dmesg

#!/bin/bash
echo "<< Log for $(date) >>" >> /var/log/mydmesg.log
dmesg >> /var/log/mydmesg.log
dmesg -C

Cron entry

0 0 * * * /path/to/your/script/log_dmesg

and may be include some log rotation logic if needed.