#! /bin/bash
CheckUrl(){
timeout=5
fails=0
success=0
while true
do
statusCode=$(curl -o /dev/null -s -w "%{http_code}\n" https://www.baidu.com/)
if [ statusCode -ne 200 ]
then
let fails=fails+1
else
let success+=1
fi
if [ $success -ge 1 ]
then
echo "恭喜你 该网站健康的在运行"
exit 0
fi
if [ $fails -ge 2 ]
then
echo "该网站一定是挂了,快去检查下吧"
exit 2
fi
done
}
CheckUrl