-
-
Save balazs-endresz/99f4edb5bd840e58ab1b42880c6f694a to your computer and use it in GitHub Desktop.
send email if new entry is made to kern.log
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 | |
# http://serverfault.com/questions/24428/monitoring-dmesg-output | |
MAILTO=root | |
LOG=/var/log/kern.log | |
OFFSET_FILE=$0.offset | |
if [ ! -f $OFFSET_FILE ]; then echo 0 > $OFFSET_FILE; fi | |
OFFSET=`cat $OFFSET_FILE` | |
FILESIZE=`cat $LOG|wc -c` | |
# Check if log has been rotated | |
if [ "$OFFSET" -gt "$FILESIZE" ]; then | |
OFFSET=0 | |
echo 0 > $OFFSET_FILE | |
fi | |
if [ "$FILESIZE" -gt "$OFFSET" ]; then | |
tail -c+$OFFSET $LOG|sed "s/^/ /"|mail $MAILTO -s "new kernel alerts" | |
echo $FILESIZE > $OFFSET_FILE | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment