linux中shell指令碼監控網站80連接埠與網站是否正常

來源:互聯網
上載者:User

監控網站80連接埠

很多時候我們不知道網站80連接埠是否正常,當然我以前的shell監控網站狀態(續)這篇文章也可以監控網站,這裡只是給大家提供另外一個思路去監控網站.

指令碼內容:

 代碼如下 複製代碼

vi check-80.sh

#!/bin/bash
nmap -P0 -p80 -sS -vv blog.slogra.com|grep 80 |tail -n1>/tmp/nmap.txt
check_80=`cat /tmp/nmap.txt|awk '{print $2}'`
if [ "$check_80" != "open" ]; then
 body="www.111cn.net port 80 is error!"
 subject="blog.slogra.com port 80 down,check it now!@from monitor `date +%T`"
 echo "${body}"| mutt -s "${subject}" rocdk@163.com
fi

shell指令碼監控網站是否正常

1. 編寫Shell指令碼,儲存到/opt/http_monitor

 代碼如下 複製代碼

#!/bin/bash

#網站url地址
URL="http://www.111cn.net/"

#擷取http響應代碼
HTTP_CODE=`curl -o /dev/null -s -w "%{http_code}" "${URL}"`
#echo $HTTP_CODE

#伺服器能正常響應,應該返回200的代碼
if [ $HTTP_CODE != 200 ];then
#重啟服務
service httpd restart
fi

2. 增加到crontab,使用crontab -e命令添加新的任務:

Shell代碼

 代碼如下 複製代碼
#每分鐘運行一次
*/1 * * * * /opt/http_monitor

3. 停掉服務,測試,cool!一分鐘後自動啟動了!可是中文亂碼了,查了一下原來是沒有載入系統變數,好辦,在http_monitor中加入locale環境變數就可以了:

Shell代碼

 代碼如下 複製代碼

export LC_ALL=zh_CN.UTF-8


注意

很多朋友使用dnspod監控,但它只能監控伺服器是否可串連,如果網站中毒了可能就無法監測了。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.