Articles
OpenWRT에서 사람이 읽을 수있는 dmesg 타임 스탬프
On 2월 17, 2021 by admindmesg의 출력은 시스템 시작 이후 초 + 밀리 초 수를 보여줍니다.
[ 10.470000] ohci_hcd: USB 1.1 "Open" Host Controller (OHCI) Driver [ 14.610000] device eth0 entered promiscuous mode [ 18.750000] cfg80211: Calling CRDA for country: DE [ 18.750000] cfg80211: Regulatory domain changed to country: DE
Q : 초 + 밀리 초를 읽을 수있는 형식으로 지정하는 방법은 무엇입니까?
내 dmesg :
root@OpenWrt:/tmp# dmesg -h dmesg: invalid option -- h BusyBox v1.19.4 (2013-03-14 11:28:31 UTC) multi-call binary. Usage: dmesg [-c] [-n LEVEL] [-s SIZE] Print or control the kernel ring buffer -c Clear ring buffer after printing -n LEVEL Set console logging level -s SIZE Buffer size
사용 가능한 공간이 많지 않기 때문에 util-Linux를 설치할 수 없습니다.
root@OpenWrt:~# df -h Filesystem Size Used Available Use% Mounted on rootfs 1.1M 956.0K 132.0K 88% / /dev/root 2.0M 2.0M 0 100% /rom tmpfs 14.3M 688.0K 13.6M 5% /tmp tmpfs 512.0K 0 512.0K 0% /dev /dev/mtdblock3 1.1M 956.0K 132.0K 88% /overlay overlayfs:/overlay 1.1M 956.0K 132.0K 88% /
.
root@OpenWrt:/tmp# which awk perl sed bash sh shell tcsh /usr/bin/awk /bin/sed /bin/sh root@OpenWrt:~# date -h date: invalid option -- h BusyBox v1.19.4 (2013-03-14 11:28:31 UTC) multi-call binary. Usage: date [OPTIONS] [+FMT] [TIME] Display time (using +FMT), or set time [-s,--set] TIME Set time to TIME -u,--utc Work in UTC (don"t convert to local time) -R,--rfc-2822 Output RFC-2822 compliant date string -I[SPEC] Output ISO-8601 compliant date string SPEC="date" (default) for date only, "hours", "minutes", or "seconds" for date and time to the indicated precision -r,--reference FILE Display last modification time of FILE -d,--date TIME Display TIME, not "now" -D FMT Use FMT for -d TIME conversion -k Set Kernel timezone from localtime and exit
댓글
답변
당신이 찾고있는 것이 -T
man dmesg
에 설명 된대로 :
-T, –ctime
인쇄 사람이 읽을 수있는 타임 스탬프입니다. 타임 스탬프가 정확하지 않을 수 있습니다.
로그에 사용 된 시간 소스는 시스템 SUSPEND / RESUME 후에 업데이트되지 않습니다.
예 :
[ 518.511925] usb 2-1.1: new low-speed USB device number 7 using ehci-pci [ 518.615735] usb 2-1.1: New USB device found, idVendor=1c4f, idProduct=0002 [ 518.615742] usb 2-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0 [ 518.615747] usb 2-1.1: Product: USB Keykoard
됩니다 :
[Mon Jan 27 16:22:42 2014] hid-generic 0003:1C4F:0002.0007: input,hidraw0: USB HID v1.10 Keyboard [USB USB Keykoard] on usb-0000:00:1d.0-1.1/input0 [Mon Jan 27 16:22:42 2014] input: USB USB Keykoard as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.1/input/input24 [Mon Jan 27 16:22:42 2014] hid-generic 0003:1C4F:0002.0008: input,hidraw1: USB HID v1.10 Device [USB USB Keykoard] on usb-0000:00:1d.0-1.1/input1
여기 에서 멋진 트릭을 찾았습니다. sed
표현식이 잘못 사용되었습니다. dmesg
div에 ]
가 둘 이상있을 때 실패 할 것이기 때문입니다. > 라인. 내가 찾은 모든 케이스에서 작동하도록 수정했습니다. dmesg
출력. 따라서 date
가 예상대로 작동한다고 가정하면 작동합니다.
base=$(cut -d "." -f1 /proc/uptime); seconds=$(date +%s); dmesg | sed "s/\]//;s/\[//;s/\([^.]\)\.\([^ ]*\)\(.*\)/\1\n\3/" | while read first; do read second; first=`date +"%d/%m/%Y %H:%M:%S" --date="@$(($seconds - $base + $first))"`; printf "[%s] %s\n" "$first" "$second"; done
출력은 다음과 같습니다.
[27/01/2014 16:14:45] usb 2-1.1: new low-speed USB device number 7 using ehci-pci [27/01/2014 16:14:45] usb 2-1.1: New USB device found, idVendor=1c4f, idProduct=0002 [27/01/2014 16:14:45] usb 2-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0 [27/01/2014 16:14:45] usb 2-1.1: Product: USB Keykoard
댓글
- 또한
-T
플래그 만 추가 할 수 있습니다.util-linux-ng-2.20.x
이상을 지원하므로 CentOS / RHEL 6.3 이하가 아닌 Ubuntu 12.04 이상을 지원합니다. - I '
dmesg
를 수년간 사용해 왔으며 지금은이 플래그에 대해서만 배웠습니다. 왜 아무도 그렇게 말하지 않았습니까? : D - @MartinvonWittich 여기도 마찬가지입니다. 오늘 처음으로 맨 페이지를 읽었습니다. 🙂
- 죄송합니다. ' t 미리 openwrt를 사용한다고 말했습니다.
- 기록을 위해서 :
dmesg -T
처럼 대답의 스크립트도 최대 절전 모드에서 잘못된 시간을 보여줍니다.
답변
dmesg
의 버전은 분명히 전체 버전이 아닙니다. –util-linux
에서 제공하지만 대신 busybox
에서 제공합니다.
busybox
는 다양한 유틸리티의 기본 사항 을 제공하지만 “멋진 기능을 모두 제공하지는 않습니다.
플래그를 terdon이 (올바로) 제안한 경우 util-linux
p에서 제공하는 dmesg
바이너리를 사용해야합니다. >
me@server:/tmp$ busybox sh BusyBox v1.21.1 (Debian 1:1.21.0-1) built-in shell (ash) Enter "help" for a list of built-in commands. /tmp $ dmesg -T dmesg: invalid option -- "T" BusyBox v1.21.1 (Debian 1:1.21.0-1) multi-call binary. Usage: dmesg [-c] [-n LEVEL] [-s SIZE] Print or control the kernel ring buffer -c Clear ring buffer after printing -n LEVEL Set console logging level -s SIZE Buffer size /tmp $ /bin/dmesg -T | tail -5 [Mon Jän 27 13:37:24 2014] hid-generic 0003:046D:C03E.0006: input,hidraw2: USB HID v1.10 Mouse [Logitech USB-PS/2 Optical Mouse] on usb-0000:00:1d.0-1.8/input0 [Mon Jän 27 15:59:32 2014] NVRM: API mismatch: the client has the version 304.117, but [Mon Jän 27 15:59:32 2014] NVRM: this kernel module has the version 304.116. Please [Mon Jän 27 15:59:32 2014] NVRM: make sure that this kernel module and all NVIDIA driver [Mon Jän 27 15:59:32 2014] NVRM: components have the same version. /tmp $
/var/log/syslog
에 기록하는 경우)에 기록하는 경우 해당 로그를 확인하십시오. 동일한 정보가 포함되어 있지만 읽을 수있는 타임 스탬프가있을 수 있습니다. .date
명령은-d
플래그를 지원하지 않습니다. 맞습니까? 그리고 내가 추측하는 파이썬도 없습니까?awk
구현은 무엇입니까? 적어도GNU awk
인가요?date -d
가 있다면 업데이트 된 답변이 작동합니다.