In RHEL 6 I have the kernel parameter:
printk.time=1
So that my dmesg would have a timestamp. However it shows in seconds from restart, like this:
[12.23456]
I found a script that you place inside .bashrc that converts the seconds to HR date.
dmesg_with_human_timestamps () {
$(type -P dmesg) "$@" | perl -w -e 'use strict;
my ($uptime) = do { local @ARGV="/proc/uptime";<>}; ($uptime) = ($uptime =~ /^(\d+)\./);
foreach my $line (<>) {
printf( ($line=~/^\[\s*(\d+)\.\d+\](.+)/) ? ( "[%s]%s\n", scalar localtime(time - $uptime + $1), $2 ) : $line )
}'
}
alias dmesg=dmesg_with_human_timestamps
This works great and my dmesg output now looks like this:
[Fri Jun 10 13:07:14 2016]
But how can I change the code to make that look like this:
[2016/06/10 13:25:28]