Advertisement
josephxsxn

dmesgTimeStamp.sh

Jul 13th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.57 KB | None | 0 0
  1. #!/bin/bash
  2. # Translate dmesg timestamps to human readable format
  3.  
  4. # desired date format
  5. date_format="%a %b %d %T %Y"
  6.  
  7. # uptime in seconds
  8. uptime=$(cut -d " " -f 1 /proc/uptime)
  9.  
  10. # run only if timestamps are enabled
  11. if [ "Y" = "$(cat /sys/module/printk/parameters/time)" ]; then
  12.   dmesg | sed "s/^\[[ ]*\?\([0-9.]*\)\] \(.*\)/\\1 \\2/" | while read timestamp message; do
  13.     printf "[%s] %s\n" "$(date --date "now - $uptime seconds + $timestamp seconds" +"${date_format}")" "$message"
  14.   done
  15. else
  16.   echo "Timestamps are disabled (/sys/module/printk/parameters/time)"
  17. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement