check web status

#!/bin/bash

sendmail() {

/usr/local/bin/sendEmail -f [email protected] -t [email protected] -s smtp.163.com -u "SERVER 192.168.31.$i" -xu [email protected] -xp "123456" -m "Alert: web 192.168.31.$i can't access"

}


while :

do

    for i in {129,202,130}

    do

        status_code=`curl -I -o /dev/null -s -w "%{http_code}\n" http://192.168.31.$i`

        if [ $status_code -ne 200 ]

        then

            sendmail

            echo `date` >> /var/log/WebAlert.log

            echo "Alert Email has been sent" >> /var/log/WebAlert.log

            echo "---------------------------------------------"

        fi

    done

sleep 10

done


你可能感兴趣的:(check web status)