Last active
October 21, 2019 01:58
-
-
Save jason-riddle/9466005cbb584f13c42dbcd93a5eeddd to your computer and use it in GitHub Desktop.
Convert dmesg timestamps to UTC format
This file contains hidden or 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
#!/bin/bash | |
# Translate dmesg timestamps to human readable format | |
# desired date format | |
date_format="%Y-%m-%dT%H:%M:%SZ" | |
# [ 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 - $(awk '{print $1}' /proc/uptime) seconds + $timestamp seconds" +"${date_format}")" "$message" | |
done | |
else | |
echo "Timestamps are disabled (/sys/module/printk/parameters/time)" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment