Skip to content

Instantly share code, notes, and snippets.

@balazs-endresz
Created September 8, 2016 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balazs-endresz/99f4edb5bd840e58ab1b42880c6f694a to your computer and use it in GitHub Desktop.
Save balazs-endresz/99f4edb5bd840e58ab1b42880c6f694a to your computer and use it in GitHub Desktop.
send email if new entry is made to kern.log
#!/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