Created
September 25, 2018 07:30
-
-
Save cakyus/1acc33417c2c99acc9136eb31358b781 to your computer and use it in GitHub Desktop.
Add timestamp to the begining of dmesg output
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 | |
# | |
# 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