Skip to content

Instantly share code, notes, and snippets.

@jason-riddle
Last active October 21, 2019 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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.
Convert dmesg timestamps to UTC format
#!/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