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

方法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)"
whilereadturl
do
url=`echo$turl|awk'{print $1}'`
msg=`echo$turl|awk'{print $2}'`
telList=`echo$turl|awk'{print $3}'`
$(curl"$url">/dev/null)
if[$?-eq0];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[$?-ne0];then
echo"${portName[$i]}:${portNum[$i]} isn't exist"
else
echo"${portName[$i]}:${portNum[$i]} is OK"
fi
done
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值