經過mutt發郵件到139郵箱實現短信報警html
監控web服務器80端口是否可用,有2種方法:web
1. 經過訪問web服務器的某個固定URL,查看返回的http狀態是否爲200;bash
2. 經過掃描web服務器的 80端口是否已開啓;服務器
建議這2種方式都用上curl
#!/bin/bashide
weblog=/root/monitor/websitemon.logurl
URL="http://www.ff-bb.cn/logs/216232462.html"code
URL2="http://www.ff-bb.cn/logs/215480720.html"htm
HTTP_CODE=`curl -o /dev/null -s -w "%{http_code}" "${URL}"`blog
HTTP_CODE2=`curl -o /dev/null -s -w "%{http_code}" "${URL2}"`
time_stamp=`date "+%Y/%m/%d %T"`
subject="ff-bb.cn不能訪問! @`date +%T`"
echo "==========webpage check====">>$weblog
echo "$time_stamp http_status= $HTTP_CODE ">>$weblog
#檢測2個URL,只有所有失敗時纔會發短信
if [ $HTTP_CODE != '200' ];then
#check it again
if [ $HTTP_CODE2 != '200' ];then
echo "ff-bb down from monitor1"| mutt -s "${subject}" 135456789@139.com
fi
fi
###如下經過nmap 掃描80端口是否可用,-P0當web服務器禁ping的狀況下使用 -p80是指只掃描80端口 增快速度和以防被防火牆放入黑名單
echo "========== web1 80 check====">>$weblog
nmap -P0 -p80 -sS -vv 1.2.3.4 |grep 80 |tail -n1>/tmp/nmap.txt
rr80=`cat /tmp/nmap.txt|awk '{print $2}'`
if [ "$rr80" != "open" ]; then
body="1.2.3.4 port80鏈接錯誤"
subject="web1 port80 down,check it now!@from monitor `date +%T`"
echo "${body}"| mutt -s "${subject}" 135456789@139.com
fi