Created
July 28, 2013 22:09
-
-
Save jaredk2g/6100469 to your computer and use it in GitHub Desktop.
Bash script to e-mail errors that show up in my nginx error log since the previous day
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 | |
SITES=( dev.inspirevive.com invoicedapp.com invoice-generator.com infuse.jaredtking.com jaredtking.com printable-calendar.co ) | |
DATE_FORMAT="+%Y/%m/%d" | |
YESTERDAY=$(date --date="yesterday" $DATE_FORMAT) | |
TODAY=$(date $DATE_FORMAT) | |
function parseLog { | |
NUM_ERRORS=0 | |
ERRORS="" | |
while read LINE | |
do | |
if [[ $LINE == $1* ]] || [[ $LINE == $2* ]] ; | |
then | |
ERRORS="$ERRORS\n$LINE" | |
NUM_ERRORS=$((NUM_ERRORS+1)) | |
fi | |
done < $3 | |
if [ "$NUM_ERRORS" -gt "0" ] ; | |
then | |
MESSAGE="Top of the morning to you,\n\n$NUM_ERRORS error(s) showed up in the $3 logs since yesterday\n\n$ERRORS" | |
echo -e $MESSAGE | mail -s "$NUM_ERRORS error(s) on $4" jared@nfuseweb.com | |
fi | |
} | |
for SITE in ${SITES[@]} | |
do | |
echo -e "\n--- Parsing log file for $SITE\n" | |
parseLog $YESTERDAY $TODAY "/var/www/log/$SITE-error.log" $SITE | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment