查看dmesg.old带时间戳

command变量可以根据自己需要修改成其他命令,比如:dmesg,其实dmesg查看时间戳可以使用dmesg -T。

#!/bin/sh
command=$(cat /var/log/dmesg.old | cut -d ']' -f1 --complement)

uptime_ts=$(cat /proc/uptime | awk '{ print $1}')

echo "${command}" | awk -v uptime_ts=$uptime_ts 'BEGIN {

    now_ts = systime();

    start_ts = now_ts - uptime_ts;

}

{

    print strftime("[%Y/%m/%d %H:%M:%S]", start_ts + substr($1, 2, length($1) - 2)), $0

}'
posted @ 2023-04-17 15:55  xzy186  阅读(381)  评论(0编辑  收藏  举报