Once in a while (just when you think you’re safe) somebody asks you when a specific event -like an I/O error- occured on a specific machine that was long lost in the battle for Eurasia, or at least, you thought it was.
As you expect, this ancient machine doesn’t support ‘dmesg -T’ in order to print the timestamp in a human readable format, so you’reĀ left wondering: “Now how did I convert these timestamps into human readable date/times again?”
I did this waaaay too many times in the past, so now I just travel with the following snippet of code in my .bashrc for old machines:
dmesg_readable () {
$(type -P dmesg) "$@" | perl -w -e 'use strict;
my ($getUptime) = do { local @ARGV="/proc/uptime";<> };
($getUptime) = ($getUptime =~ /^(\d+)\./);
foreach my $line (<>) {
printf( ($line=~/^\[\s*(\d+)\.\d+\](.+)/) ? ( "[%s]%s\n", scalar localtime(time - $getUptime + $1), $2 ) : $line )
}'
}
alias dmesg=dmesg_readable
There are probably easier (or better) ways to get it done, but this sure works for me.