Last active
August 29, 2015 14:16
-
-
Save TobleMiner/cde1825190f66893710d to your computer and use it in GitHub Desktop.
Dmesg human readable timestamps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
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 { | |
my @time = localtime $_[0]; | |
$time[4]+=1; # Adjust month | |
$time[5]+=1900; # Adjust year | |
return sprintf '%4i-%02i-%02i %02i:%02i:%02i', @time[reverse 0..5]; | |
} | |
foreach my $line ( @dmesg_old ) | |
{ | |
chomp( $line ); | |
if( $line =~ m/\[\s*(\d+)\.(\d+)\](.*)/i ) | |
{ | |
# now - uptime + seconds | |
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