Determine the status code of a website, and intercept the status code to determine whether the status code is 200. URL is the corresponding URL, and the test can use www.baidu.com. Abnormal URL can be used

#!/bin/bash
ma=`curl -I  /dev/null -s  www.baidu.com | grep HTTP/1.1 | awk  '{print$2}'`#截取状态码
if [ $ma -eq 200 ];then
        echo "状态正常"
else
        echo "状态不正常" | mail -s "状态码不正常" 656632323@qq.com
fi

Guess you like

Origin blog.csdn.net/zhangthree1/article/details/109129862