新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
使用Shell腳本的方式監(jiān)控WEB服務(wù)狀態(tài)
實(shí)際工作中我們需要知道部署在服務(wù)器上的應(yīng)用有沒有問題,但是人為的操作太麻煩,最簡(jiǎn)單的方式就是sehll腳本的方式,下面為大家分享一下使用Shell腳本監(jiān)控WEB服務(wù)狀態(tài)具體方法。

我們提供的服務(wù)有:網(wǎng)站建設(shè)、網(wǎng)站制作、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、泌陽ssl等。為1000+企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的泌陽網(wǎng)站制作公司
安裝sendmail來發(fā)郵件
# yum -y install sendmail
# /etc/init.d/sendmail start
# chkconfig sendmail on
安裝mutt郵件客戶端,并設(shè)置相關(guān)信息
# yum -y install mutt
# vim /etc/Muttrc
set charset="utf-8" #設(shè)置發(fā)郵件編碼
set envelope_from=yes
set rfc2047_parameters=yes #解決附件亂碼問題
set realname="報(bào)警" #發(fā)件人別名
set use_from=yes #指定是否顯示別名
set from=monitor@test.com #發(fā)送人地址
腳本如下
#!/bin/bash
Mail="xingzhiwei@163.com"
FailCount=0
Retval=0 GetUrlStatus() { for ((i=1;i#使用i++判斷訪問次數(shù),如果wget兩次超時(shí)則判斷網(wǎng)站異常
do
wget -T 3 --tries=1 --spider http://${1} >/dev/null 2>&1 #-T超時(shí)時(shí)間,--tries嘗試1次,--spider蜘蛛
[ $? -ne 0 ] && let FailCount+=1; #訪問超時(shí)時(shí),$?不等于0,則FailCount加1
done
if [ $FailCount -gt 1 ];then
Retval=1
Date=`date +%F" "%H:%M` echo -e "Date : $Date Problem : $url is not running." | mutt -s "URL Monitor" $Mail
else
Retval=0 fi
return $Retval #如果返回值為0,就正常退出循環(huán),不為0則繼續(xù)循環(huán)
}for url in `cat url | sed '/^#/d'`do
#GetUrlStatus $url && echo yes || echo no
GetUrlStatus $urldonesleep 2m #死循環(huán),設(shè)置沒2分鐘運(yùn)行一次don
網(wǎng)站題目:使用Shell腳本的方式監(jiān)控WEB服務(wù)狀態(tài)
URL分享:http://www.dlmjj.cn/article/cccehsd.html


咨詢
建站咨詢
