Skip to content

Instantly share code, notes, and snippets.

@jason-riddle
Last active October 21, 2019 01:58
Show Gist options
  • Save jason-riddle/9466005cbb584f13c42dbcd93a5eeddd to your computer and use it in GitHub Desktop.
Save jason-riddle/9466005cbb584f13c42dbcd93a5eeddd to your computer and use it in GitHub Desktop.

Revisions

  1. jason-riddle revised this gist Oct 21, 2019. 1 changed file with 1 addition and 5 deletions.
    6 changes: 1 addition & 5 deletions dmesg_to_utc.sh
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,6 @@
    # desired date format
    date_format="%Y-%m-%dT%H:%M:%SZ"

    # uptime in seconds
    # 2153.54 1953.49
    uptime=$(awk '{print $1}' /proc/uptime)

    # [ 3.469072] EXT4-fs (xvda1): mounted filesystem with ordered data mode. Opts: (null)
    # [ 3.483769] dracut: Remounting /dev/disk/by-label/\x2f with -o noatime,ro
    # [ 3.495019] EXT4-fs (xvda1): mounted filesystem with ordered data mode. Opts: (null)
    @@ -16,7 +12,7 @@ uptime=$(awk '{print $1}' /proc/uptime)
    # run only if timestamps are enabled
    if [ "Y" = "$(cat /sys/module/printk/parameters/time)" ]; then
    dmesg | sed "s/^\[[ ]*\?\([0-9.]*\)\] \(.*\)/\\1 \\2/" | while read timestamp message; do
    printf "[%s] %s\n" "$(date --date "now - $uptime seconds + $timestamp seconds" +"${date_format}")" "$message"
    printf "[%s] %s\n" "$(date --date "now - $(awk '{print $1}' /proc/uptime) seconds + $timestamp seconds" +"${date_format}")" "$message"
    done
    else
    echo "Timestamps are disabled (/sys/module/printk/parameters/time)"
  2. jason-riddle created this gist Oct 21, 2019.
    23 changes: 23 additions & 0 deletions dmesg_to_utc.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/bin/bash
    # Translate dmesg timestamps to human readable format

    # desired date format
    date_format="%Y-%m-%dT%H:%M:%SZ"

    # uptime in seconds
    # 2153.54 1953.49
    uptime=$(awk '{print $1}' /proc/uptime)

    # [ 3.469072] EXT4-fs (xvda1): mounted filesystem with ordered data mode. Opts: (null)
    # [ 3.483769] dracut: Remounting /dev/disk/by-label/\x2f with -o noatime,ro
    # [ 3.495019] EXT4-fs (xvda1): mounted filesystem with ordered data mode. Opts: (null)
    # [ 3.506417] dracut: Mounted root filesystem /dev/xvda1

    # run only if timestamps are enabled
    if [ "Y" = "$(cat /sys/module/printk/parameters/time)" ]; then
    dmesg | sed "s/^\[[ ]*\?\([0-9.]*\)\] \(.*\)/\\1 \\2/" | while read timestamp message; do
    printf "[%s] %s\n" "$(date --date "now - $uptime seconds + $timestamp seconds" +"${date_format}")" "$message"
    done
    else
    echo "Timestamps are disabled (/sys/module/printk/parameters/time)"
    fi