#!/bin/bash cd "$(dirname "$(readlink -f "$0")")" # Test if config.cfg exists and set needed variables if [ ! -e config.cfg ]; then echo "Missing config.cfg file. Edit and rename config.cfg.sample"; exit 1; fi source config.cfg function fappend { echo -e "$2">>$1; } function mailsend { TOEMAIL="$TOEMAIL"; FREMAIL="$FREMAIL"; SUBJECT="[EWM] $1"; MSGBODY1="$2" MSGBODY2="$3" TMP=`mktemp` fappend $TMP "From: $FREMAIL"; fappend $TMP "To: $TOEMAIL"; fappend $TMP "Reply-To: $FREMAIL"; fappend $TMP "Subject: $SUBJECT"; fappend $TMP ""; fappend $TMP "$MSGBODY1"; fappend $TMP ""; fappend $TMP "$MSGBODY2"; fappend $TMP ""; cat $TMP | "$SENDMAILPATH" -t; rm $TMP; } function pingtest { ping -c3 -W3 -q $1 STATUS=$(echo $?) } function indextest { wget -q -T 5 -t 2 -U $(cat monitor-user-agent.txt) -O "$CURHOST".html http://"$CURHOST" if [ -e sites/"$CURHOST".ignore ]; then CURIGN=$(cat sites/"$CURHOST".ignore) else CURIGN="VeRy-UnLiKeLy-StRiNg-To-MaTcH" fi diff -qBb -I $CURIGN sites/"$CURHOST".orig "$CURHOST".html STATUS=$(echo $?) } for ((i = 0; i < ${#NAME[*]}; i++)); do CURNAME=${NAME[$i]} CURHOST=${HOST[$i]} ## TEST PING pingtest $CURHOST if [ "$STATUS" != 0 ]; then mailsend "Ping error on $CURHOST" \ "Ping was unsuccessful" \ "Check http://$CURHOST" fi ## TEST FOR CHANGED INDEX indextest if [ "$STATUS" != 0 ]; then diff -U 0 -Bb -I $CURIGN sites/"$CURHOST".orig "$CURHOST".html > "$CURHOST".diff mailsend "Index error on $CURHOST" \ "Index on $CURHOST differs from original index: \n\n$(cat $CURHOST.diff)" \ "Update original index: ssh://$CURNAME" rm "$CURHOST".diff fi rm "$CURHOST".html done