一個監控WEB服務是否正常的shell
阿新 • • 發佈:2019-02-04
方法1:
#! /bin/bash
. /etc/profile
. /root/.bash_profile
export PATH
export LC_ALL=zh_CN
mysql -e "select url,msg,telList from monitor.url where checkStatus='1';" -ss >/tmp/url.tmp
URL="http://10.0.0.5/addmessage.php?type=checkUrl&host=$(hostname)"
while read turl
do
url=`echo $turl |awk '{print $1}'`
msg=` echo $turl | awk '{print
$2}'`
telList=`echo $turl | awk '{print $3}'`
$(curl "$url" >/dev/null)
if [ $? -eq 0 ]; then
echo "$url OK"
else
`echo "$url error"`
echo "$URL&msg=$msg"
curl "$URL&tel=$telList&msg=$msg"
/monitor/shell/sms.sh
fi
done < /tmp/url.tmp
$(rm -f /monitor/shell/htmltmp/*.*)
url.tmp的內容格式如下:
監控url的地址 傳送資訊內容 接收手機號碼
http://www.sina.com.cn 新浪網首頁不能開啟 1348067****
方法2:檢查httpd、ftp、這些服務的埠,以達到檢測的目的。
#!/bin/bash
export LC_ALL=zh_CN
ports="3306 80 21" #定義要監控的埠
service="Mysql資料庫 WEB服務 FTP服務"
portNum= ($(echo $ports))
portName=($(echo $service))
for ((i=0;i<${#portNum[@]};i++)); do
/bin/netstat -tulpn | grep -vE '^Active|Proto'|grep ${portNum[$i]} >/dev/null
if [ $? -ne 0 ]; then
echo "${portName[$i]}:${portNum[$i]} isn't exist"
else
echo "${portName[$i]}:${portNum[$i]} is OK"
fi
done
#! /bin/bash
. /etc/profile
. /root/.bash_profile
export PATH
export LC_ALL=zh_CN
mysql -e "select url,msg,telList from monitor.url where checkStatus='1';" -ss >/tmp/url.tmp
URL="http://10.0.0.5/addmessage.php?type=checkUrl&host=$(hostname)"
while read turl
do
url=`echo $turl |awk '{print $1}'`
msg=`
telList=`echo $turl | awk '{print $3}'`
$(curl "$url" >/dev/null)
if [ $? -eq 0 ]; then
echo "$url OK"
else
`echo "$url error"`
echo "$URL&msg=$msg"
curl "$URL&tel=$telList&msg=$msg"
/monitor/shell/sms.sh
fi
done <
$(rm -f /monitor/shell/htmltmp/*.*)
url.tmp的內容格式如下:
監控url的地址 傳送資訊內容 接收手機號碼
http://www.sina.com.cn 新浪網首頁不能開啟 1348067****
方法2:檢查httpd、ftp、這些服務的埠,以達到檢測的目的。
#!/bin/bash
export LC_ALL=zh_CN
ports="3306 80 21" #定義要監控的埠
service="Mysql資料庫 WEB服務 FTP服務"
portNum=
portName=($(echo $service))
for ((i=0;i<${#portNum[@]};i++)); do
/bin/netstat -tulpn | grep -vE '^Active|Proto'|grep ${portNum[$i]} >/dev/null
if [ $? -ne 0 ]; then
echo "${portName[$i]}:${portNum[$i]} isn't exist"
else
echo "${portName[$i]}:${portNum[$i]} is OK"
fi
done