• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ping发现掉包报警的shell代码

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
复制代码 代码如下:

#!/bin/bash
PING=`which ping`
DATE=`date +%Y%m%d%H%M`
TAIL=`which tail`
LOG=./ping$DATE.log
HOSTS="selboo.com.cn 221.130.191.97"
COUNT=200
for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep ‘loss' | awk -F',' '{ print $3 }' | awk -F “%” ‘{ print $1 }')
if [ $count -ge 10 ]; then
/bin/echo selboo | mutt -s "$myHost pingispacketloss>10% $DATE" [email protected]
fi
done
exit 0

复制上以上内容为ping.sh加入crontab中让其10分钟跑一次,其中发邮件程序为mutt

以下是补充:

linux 的和solaris的居然不一样!
复制代码 代码如下:

#!/bin/sh
PingConf='/opt/monitor/newIp'
#File where the log will be stored
LogDir='/opt/monitor/newLog'
#Define the interval time
INTERVAL='10'
#Define the alarm process
########################################################
proc_main()
{
while read IpAddress
do
#ingore any hash signs
case $IpAddress in
#*);;
*)
ping -w 20 $IpAddress -c 5 >errtmp$$
# ping $IpAddress -c 10 >errtmp$$
if [ $? = 0 ] ; then
rm errtmp$$
else
rm errtmp$$
ErrTime=`date +%Y/%m/%d/%H:%M:%S`
# echo "$ErrTime"": ""$IpAddress"" cann't be connected">>$LogDir
echo "$ErrTime"":""$IpAddress"" cann't be connected
">>$LogDir
sleep 1
cp /opt/monitor/newLog /opt/OV/www/htdocs/PingLog/new.html
sleep 1
# mail -s "$IpAddress"Cantreach -c 我的email </dev/null
play -v 50 /opt/monitor/123.au
fi
esac
done <$PingConf
}
##########################################################
# execute the proc_main function every the specified time INTERVAL
while [ "1" -eq "1" ]
do

# execute the proc_main function
proc_main
# suspend execution for INTERVAL seconds
sleep $INTERVAL
done

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
linux 监视端口是否正常的shell脚本发布时间:2022-02-11
下一篇:
Shell常见知识 方便想学习linux shell的彭玉发布时间:2022-02-11
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap