initial commit v1.0
This commit is contained in:
Executable
+79
@@ -0,0 +1,79 @@
|
||||
#!/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="mail@mehl.mx";
|
||||
FREMAIL="tech@mehl.mx";
|
||||
SUBJECT="[MON] $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 | /usr/sbin/sendmail -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 $CURNAME" \
|
||||
"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 $CURNAME" \
|
||||
"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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user