Human readable dmesg time stamps on OpenWRT
I think that what you're looking for is -T
as documented in man dmesg
:
-T, --ctime
Print human readable timestamps. The timestamp could be inaccurate!
The time source used for the logs is not updated after system SUSPEND/RESUME.
So, for example:
[ 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
Becomes:
[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
I found a cool trick here. The sed
expression used there was wrong since it would fail when there was more than one ]
in the dmesg
line. I have modified it to work with all cases I found in my own dmesg
output. So, this should work assuming your date
behaves as expected:
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
Output looks like:
[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
your version of dmesg
is obviously not the full-fledged one from util-linux
but instead is provided by busybox
.
busybox
provides the basics of a multitude of utilities, but it doesn't provide all their nifty features.
if you want to use the -T
flag as (rightly) suggested by terdon, you will need to use the dmesg
binary provided by util-linux
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 $