1、
http://www.taodudu.cc/news/show-316388.html?action=onClick
网卡或者硬盘有问题时,我们可以通过使用dmessage命令查看相关信息
直接用dmesg显示系统信息,很难看
[95721.670025] snapshot device recevied [read] io request, access on dev sector[272], length is [240] sectors.
[95721.670363] device is closed
[95721.693207] device is closed
显示的时间没有办法看。
使用dmesg --help看到,如下:
Usage:
dmesg [options]
Display or control the kernel ring buffer.
Options:
-C, --clear clear the kernel ring buffer
-c, --read-clear read and clear all messages
-D, --console-off disable printing messages to console
-E, --console-on enable printing messages to console
-F, --file <file> use the file instead of the kernel log buffer
-f, --facility <list> restrict output to defined facilities
-H, --human human readable output
-k, --kernel display kernel messages
-L, --color[=<when>] colorize messages (auto, always or never)
colors are enabled by default
-l, --level <list> restrict output to defined levels
-n, --console-level <level> set level of messages printed to console
-P, --nopager do not pipe output into a pager
-r, --raw print the raw message buffer
-S, --syslog force to use syslog(2) rather than /dev/kmsg
-s, --buffer-size <size> buffer size to query the kernel ring buffer
-u, --userspace display userspace messages
-w, --follow wait for new messages
-x, --decode decode facility and level to readable string
-d, --show-delta show time delta between printed messages
-e, --reltime show local time and time delta in readable format
-T, --ctime show human readable timestamp (may be inaccurate!)
-t, --notime don't print messages timestamp
--time-format <format> show time stamp using format:
[delta|reltime|ctime|notime|iso]
Suspending/resume will make ctime and iso timestamps inaccurate.
-h, --help display this help and exit
可以使用-T来显示可读时间,如下:
dmesg -T
[Fri Aug 31 17:55:32 2018] device is closed
[Fri Aug 31 17:55:32 2018] device is closed
二、
https://blog.csdn.net/a1809032425/article/details/129345486
centos7 下可以直接用 dmesg -T 命令将时间戳输出为可读格式, unbuntu 下需要下面的操作:
1.获取dmesg的时间戳
# dmesg
[ 18.204448] Bluetooth: RFCOMM socket layer initialized
[ 18.204452] Bluetooth: RFCOMM ver 1.11
2.时间戳表示的含义
dmesg 日志中的“时间”(18.204452) 表示的是系统启动到事件发生的时间差,这个值可以转换成时间戳:
unix_time=`echo "$(date +%s) - $(cat /proc/uptime | cut -f 1 -d' ') + 18.204452 " | bc`
echo ${unix_time}
注:/proc/uptime 第一列表示的是系统开机时间,根据这个值和当前时间可以获取到 dmesg 日志中事件发生的时间
3.把时间戳转换为对应的可读的时间
date -d "@${unix_time}" '+%Y-%m-%d %H:%M:%S'
4.脚本文件如下
#!/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`
stamp=`echo "scale=0; ${unix_time} / 1" | bc`
echo ${stamp}
date -d @${stamp} "+%Y-%m-%d %H:%M:%S"
5. 脚本运行实例
# ./test.sh 18.204452
1538100496.004452
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?