Linux:dmesg的时间戳转换为可阅读的形式 |
您所在的位置:网站首页 › 时间戳转换命令 › Linux:dmesg的时间戳转换为可阅读的形式 |
dmesg的时间戳
dmesg 日志中的“时间”(18.204452) 表示的是系统启动到事件发生的时间差,这个值可以转换成时间戳: unix_time=`echo "$(date +%s) - $(cat /proc/uptime | cut -f 1 -d' ') + 18.204452 " | bc` echo ${unix_time}注:/proc/uptime 第一列表示的是系统开机时间,根据这个值和当前时间可以获取到 dmesg 日志中事件发生的时间。 时间戳转换为对应的可读的时间 date -d "@${unix_time}" '+%Y-%m-%d %H:%M:%S' 转换脚本 #!/bin/bash if [ $# -ne 1 ];then echo "input an dmesg time" exit 1 fi unix_time=`echo "$(date +%s) - $(cat /proc/uptime | cut -f 1 -d' ') + ${1}" | bc` echo ${unix_time} date -d "@${unix_time}" '+%Y-%m-%d %H:%M:%S' 运行示例 # ./test.sh 18.204452 1538100496.004452 2018-09-28 10:08:16 扩展dmesg -h 查看帮助 -T,–ctime 打印人类可读的时间戳 #dmesg -T
|
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |