Chinaunix首页 | 论坛 | 博客
  • 博客访问: 141366
  • 博文数量: 27
  • 博客积分: 2196
  • 博客等级: 大尉
  • 技术积分: 330
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-17 10:29
文章存档

2008年(27)

我的朋友

分类:

2008-08-28 12:26:43

方法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="(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的地址                     发送信息内容                    接收手机号码
    新浪网首页不能打开            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

阅读(1979) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~