一个监控WEB服务是否正常的shell

方法1:

#! /bin/bash

. /etc/profile
. /root/.bash_profile
export PATH
export LC_ALL=zh_CN
mysql -"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 -/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

你可能感兴趣的:(数据库,mysql,shell,service,url,web服务)