How do I convert dmesg timestamp to custom date format?

前端 未结 9 1256
感动是毒
感动是毒 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:28

    So KevZero requested a less kludgy solution, so I came up with the following:

    sed -r 's#^\[([0-9]+\.[0-9]+)\](.*)#echo -n "[";echo -n $(date --date="@$(echo "$(grep btime /proc/stat|cut -d " " -f 2)+\1" | bc)" +"%c");echo -n "]";echo -n "\2"#e'
    

    Here's an example:

    $ dmesg|tail | sed -r 's#^\[([0-9]+\.[0-9]+)\](.*)#echo -n "[";echo -n $(date --date="@$(echo "$(grep btime /proc/stat|cut -d " " -f 2)+\1" | bc)" +"%c");echo -n "]";echo -n "\2"#e'
    [2015-12-09T04:29:20 COT] cfg80211:   (57240000 KHz - 63720000 KHz @ 2160000 KHz), (N/A, 0 mBm), (N/A)
    [2015-12-09T04:29:23 COT] wlp3s0: authenticate with dc:9f:db:92:d3:07
    [2015-12-09T04:29:23 COT] wlp3s0: send auth to dc:9f:db:92:d3:07 (try 1/3)
    [2015-12-09T04:29:23 COT] wlp3s0: authenticated
    [2015-12-09T04:29:23 COT] wlp3s0: associate with dc:9f:db:92:d3:07 (try 1/3)
    [2015-12-09T04:29:23 COT] wlp3s0: RX AssocResp from dc:9f:db:92:d3:07 (capab=0x431 status=0 aid=6)
    [2015-12-09T04:29:23 COT] wlp3s0: associated
    [2015-12-09T04:29:56 COT] thinkpad_acpi: EC reports that Thermal Table has changed
    [2015-12-09T04:29:59 COT] i915 0000:00:02.0: BAR 6: [??? 0x00000000 flags 0x2] has bogus alignment
    [2015-12-09T05:00:52 COT] thinkpad_acpi: EC reports that Thermal Table has changed
    

    If you want it to perform a bit better, put the timestamp from proc into a variable instead :)

提交回复
热议问题