Created
January 9, 2016 20:34
-
-
Save Chion82/4dd175eb49d1f8fb3f3d to your computer and use it in GitHub Desktop.
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 | |
LOG_FILE=/var/log/xiaoyu/error.log | |
ERROR_KEYWORD="Error" | |
EMAIL="sdspeedonion@gmail.com" | |
SUBJECT="Error Report from loveoncampus.cn" | |
PREFIX="<h2>Error detected on server loveoncampus!</h2><br/>Error log:<br/><div style='background-color:#f1f1f1;padding:10px;'>" | |
FOLLOW="</div>" | |
LAST_LOG_TIME=$(stat -c %Y $LOG_FILE) | |
while true; do | |
NEW_LOG_TIME=$(stat -c %Y $LOG_FILE) | |
if [[ $NEW_LOG_TIME != $LAST_LOG_TIME ]] ; then | |
LOG_TAIL=$(tail $LOG_FILE -n 100) | |
echo "Error detected:" | |
echo $LOG_TAIL | |
echo "Sending notification mail." | |
echo ${PREFIX}${LOG_TAIL}${FOLLOW} | mailx -s "$(echo -e "${SUBJECT}\nContent-Type: text/html")" ${EMAIL} | |
fi | |
LAST_LOG_TIME=$NEW_LOG_TIME | |
sleep 2 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment