Converting dmesg date and time to human-readable form

One of the drawbacks with dmesg is the native date time stamps are not in human-readable form.

Unfortunately, the OpenWRT implementation of Linux is not full-stack, so the -T option is not available to convert them.

However, there is a pretty clever script that was published on the StackExchange Unix & Linux forum by @terdon that works well...

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"; 

Copy, paste, and run all at once.

The dmesg output will have human-readable date and time stamps.


would be interesting to implementi this on luci... (considering new luci is all clientside would impact 0 on the router load to handle this)

What I can't understand is.... how does it work?

we subtract the uptime from the current time and then we calculate the time based on that value (knowing the time when the device booted?)

Will add this to my freetime list.

This (implementing this in LuCI) would be useful. I created a script that retrieves a standard set of diagnostic data for debugging

It retrieves data using both logread and dmesg and it would be slick to have the latter time stamps more human-readable.

1 Like