一个ping检测告警函数代码
2018-10-12 14:11
477 查看
#!/bin/bash
ping_monitor()
{
host_=(203 204 205 207 208 209 210 212 213 214 215 216 217 218 219 220 221)
ping_count=3
called=(13000000001 13000000002 13000000003)
calling=13000000000
callop=1310000000
#main------------------------------------------------------------
echo "`date "+%Y%m%d %H:%M:%S"`----->脚本开始执行......">>ping_log
for host_1 in ${host_[*]};do
host=192.168.1.$host_1
echo "-------->开始检测$host服务器通迅是否正常,ping次数$count"
ping_result=`ping $host -c $ping_count |tail -2 |head -1`
#sleep 1
echo "-------->服务器$host检测已完成"
#取成功条数
succ_ping=`echo ${ping_result:23:1}`
#取失败百分比
loss_ping=`echo ${ping_result:46:4}`
if [ $succ_ping -eq $ping_count ];then
echo "本次检测结果---->$host服务器ping检测正常"
echo "`date "+%Y%m%d %H:%M:%S"`--->$host服务器ping检测正常" >>ping_log
else
echo "本次检测结果---->$host服务器有丢包现象,丢包率为:$loss_ping"
echo "`date "+%Y%m%d %H:%M:%S"`--->$host服务器有丢包现象,丢包率为:$loss_ping" >>ping_err_log
#插入短信表―smssend00
for called in ${telno[*]};do
mysql -h$dbhost -u$dbuser -p$dbpass -D$dbbase <<GETRECODE
INSERT INTO $dbtable (servercode,smsservercode,groupid,priority,calling,called,payer,orderdatetime,senddatetime,effectstarttime,
effectendtime,effectstarttime2,effectendtime2,invaliddatetime,feevalue,iffee,message,hideflag,msgtype,smsfeetype,ifsmsreport,service
type,morelatetomtflag,reserve,optempid,optuserid,clientprogramtype,optcode,optip,remark)
VALUES
(2,2,1,0,'$calling','$called','$callop',Now(),Now(),'00:00:00','23:59:59',NULL,NULL,NULL,0,1,'服务器告警!!$host服务器检测到有丢包现像,丢包率:$loss_ping',0,1,2,0,'2_2',NULL,NULL,1,668,1,3001,'192.168.1.182',NULL)
GETRECODE
done
fi
done
echo "`date "+%Y%m%d %H:%M:%S"`----->脚本运行完毕......">>ping_log
}
相关文章推荐
- 一个ping检测告警函数代码
- Coldfusion里一个不错的检测函数isvalid
- ASP下检测图片木马的函数代码
- 分享一个记录当前代码信息的函数
- ARC中用代码检测一个对象有没有释放掉
- 使用VC内嵌Python实现的一个代码检测工具
- VB6 如何添加自定义函数 模块 把代码放到一个模块中
- VS 用RasDial结果返回 "检测到一个不正确的结构大小"错误代码632 VS2010 VC6正常,怎解?!
- 在C++里一个类成员函数多少行代码才是最好呢?
- 发一个用状态机实现的按键检测是VERILOG代码
- 一个没有用了的函数,检测是否有重复段落。
- 一个简单的ping代码(转载的)
- 计算机笔试题:写一个函数,检查字符是否是整数,如果是,返回其整数值。(或者:怎样只用4行代码编写出一个从字符串到长整型的函数)
- 不使用汇编在vc中转换类的成员函数为一个线程的通用代码
- 一个函数5行代码即可实现完整的面向方面AOP编程功能
- 如下代码中greater10函数调用时实参是如何传递的呢? 代码是MSDN中的一个例子
- 2、检查一个字符是否是整数或者4行代码从一个字符串到长整形函数
- 我在csdn得分最多的一个帖子:用6行代码写一个将小写金额转成大写的函数
- 如何在后台CS代码文件中调用前台JS文件中的某一个函数
- 一个可交互的并发ping检测脚本