DMesg with human readable timestamps



Published: 2017-08-30 12:26:23 +0000
Categories: BASH,

Language

BASH

Description

By default, dmesg uses seconds of uptime for it's timestamps, which in less than useful if you're trying to quickly check the time an entry was logged at. Where available /var/log/kern.log can be used to get timestamped entries, but where not available the function below gives a dmesg analog with human readable timestamps

Snippet

dmesg_human() {
    $(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 )
        }'
}

Usage Example

dmesg_human

Keywords

dmesg, linux, bash, human, readable, timestamp,

Latest Posts


Copyright © 2019 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk, yr4pnhounvdybotb.onion and snippets.6zdgh5a5e6zpchdz.onion