使い方
web_alive.sh [監視URL] [停止時のメールアドレス]
#!/bin/bash
if [ $# -eq 2 ]; then
URL=$1
MAILTO=$2
else
echo "usage : $0 check_url alert_mail_address"
exit 1
fi
TIMEOUT=120
TRYCOUNT=1
SUBJECT="ALERT:Web Server is Fail!!!!"
alive=`wget -S --spider -t $TRYCOUNT -T $TIMEOUT $URL 2>&1 | grep -c "200 OK"`
if [ $alive == 0 ] ; then
echo "$URL is down." | mail -s "$SUBJECT" $MAILTO
/etc/init.d/httpd restart
else
date
echo "ok"
fi
コメント