Last active
October 6, 2019 03:54
-
-
Save rubnet/8161a55fbb85a65ae2485103623624fa to your computer and use it in GitHub Desktop.
Translate dmesg timestamps to human readable format
This file contains 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 | |
# https://blog.sleeplessbeastie.eu/2013/10/31/how-to-deal-with-dmesg-timestamps/ | |
# desired date format | |
date_format="%a %b %d %T %Y" | |
# uptime in seconds | |
uptime=$(cut -d " " -f 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" | |
done | |
else | |
echo "Timestamps are disabled (/sys/module/printk/parameters/time)( grubby --update-kernel=ALL --args='printk.time=1' only centos)" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment