Skip to content

Instantly share code, notes, and snippets.

@cakyus
Created September 25, 2018 07:30
Show Gist options
  • Save cakyus/1acc33417c2c99acc9136eb31358b781 to your computer and use it in GitHub Desktop.
Save cakyus/1acc33417c2c99acc9136eb31358b781 to your computer and use it in GitHub Desktop.
Add timestamp to the begining of dmesg output
#!/bin/bash
#
# watch-dmesg.bash
#
# Add timestamp to the begining of dmesg output
# This is only usefull when dmesg does not support "-T" parameter
#
# Crontab Entry
# * * * * * /bin/bash /home/centos/bin/watch-dmesg.bash
BASE_NAME=watch-dmesg
cd /home/centos/bin
dmesg > $BASE_NAME.prev
if [ ! -f $BASE_NAME.prev ]; then
touch $BASE_NAME.prev
fi
if [ ! -f $BASE_NAME.text ]; then
touch $BASE_NAME.text
fi
LINE_END_COUNT=$( wc -l $BASE_NAME.prev | awk '{print $1}' )
LINE_BEGIN_COUNT=$( wc -l $BASE_NAME.text | awk '{print $1}' )
tail -n $(( $LINE_END_COUNT - $LINE_BEGIN_COUNT )) $BASE_NAME.prev | \
awk '{ print strftime(), $0; fflush() }' \
>> $BASE_NAME.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment