Difference between revisions of "Dmesg Real Dates/TImestamps"

From TheBeard Science Project Wiki
Jump to: navigation, search
(Created page with "Dmesg shows timestamps in seconds since the last boot, and newer versions of dmesg take the "-T" parameter like <code>dmesg -T</code> to display dates in human readable format...")
 
 
Line 1: Line 1:
Dmesg shows timestamps in seconds since the last boot, and newer versions of dmesg take the "-T" parameter like <code>dmesg -T</code> to display dates in human readable format, but in case your server is running an old version, here's a great bash function that I stole from someone else. Keep in mind that if the system has been put to sleep, suspended, or hibernated then the timestamps will be inaccurate.
+
Dmesg shows timestamps in seconds since the last boot, and newer versions of dmesg take the "-T" parameter like <code>dmesg -T</code> to display dates in human readable format, but in case your server is running an old version here's a great bash function that provides that functionality. I didn't write this I stole it from someone else. Keep in mind that if the system has been put to sleep, suspended, or hibernated then the timestamps will be inaccurate.
  
 
<source lang="sh">
 
<source lang="sh">

Latest revision as of 01:48, 21 January 2021

Dmesg shows timestamps in seconds since the last boot, and newer versions of dmesg take the "-T" parameter like dmesg -T to display dates in human readable format, but in case your server is running an old version here's a great bash function that provides that functionality. I didn't write this I stole it from someone else. Keep in mind that if the system has been put to sleep, suspended, or hibernated then the timestamps will be inaccurate.

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