How do I convert dmesg timestamp to custom date format?

前端 未结 9 1261
感动是毒
感动是毒 2020-12-12 17:41

I am trying to understand the dmesg timestamp and find it hard to convert that to change it to java date/custom date format.

Sample dmesg log:

<         


        
9条回答
  •  难免孤独
    2020-12-12 18:27

    With the help of dr answer, I wrote a workaround that makes the conversion to put in your .bashrc. It won't break anything if you don't have any timestamp or already correct timestamps.

    dmesg_with_human_timestamps () {
        $(type -P dmesg) "$@" | perl -w -e 'use strict;
            my ($uptime) = do { local @ARGV="/proc/uptime";<>}; ($uptime) = ($uptime =~ /^(\d+)\./);
            foreach my $line (<>) {
                printf( ($line=~/^\[\s*(\d+)\.\d+\](.+)/) ? ( "[%s]%s\n", scalar localtime(time - $uptime + $1), $2 ) : $line )
            }'
    }
    alias dmesg=dmesg_with_human_timestamps
    

    Also, a good reading on the dmesg timestamp conversion logic & how to enable timestamps when there are none: https://supportcenter.checkpoint.com/supportcenter/portal?eventSubmit_doGoviewsolutiondetails=&solutionid=sk92677

提交回复
热议问题