Skip to content

Instantly share code, notes, and snippets.

@alambike
Last active December 27, 2015 01:29
Show Gist options
  • Save alambike/7245847 to your computer and use it in GitHub Desktop.
Save alambike/7245847 to your computer and use it in GitHub Desktop.
dmesg in human readable time format. Based in "http://linuxaria.com/article/how-to-make-dmesg-timestamp-human-readable"
#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw(strftime);
my @dmesg_new = ();
my $dmesg = "/bin/dmesg";
my @dmesg_old = `$dmesg`;
my $now = time();
my $uptime = `cat /proc/uptime | cut -d"." -f1`;
my $t_now = $now - $uptime;
sub format_time {
return strftime "%Y-%m-%d %H:%M:%S", localtime $_[0];
}
foreach my $line ( @dmesg_old )
{
chomp( $line );
if( $line =~ m/\[\s*(\d+)\.(\d+)\](.*)/i )
{
# now - uptime + sekunden
my $t_time = format_time( $t_now + $1 );
push( @dmesg_new , "[$t_time] $3" );
}
}
print join( "\n", @dmesg_new );
print "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment