Dmesg Real Dates/TImestamps

From TheBeard Science Project Wiki
Revision as of 01:46, 21 January 2021 by Beard (talk | contribs) (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...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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 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_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