linux 求助shell脚本 ping命令延迟超过100ms的包就发邮件 恢复正常也发个邮件 之后不用发

2025-04-05 02:07:36
推荐回答(2个)
回答1:

我的需求是PING这个地址 只要延迟高于100ms就发送个邮件 然后正常后在发个邮件通知 之后正常不发 一有延迟就发 我这个老是重复 求高人指点 #!/bin/bashIP=`ping 8.8.8.8 -c 3|sed -n "2p" |awk '{print $7}'|cut -f 2 -d "="|cut -f 1 -d "."`L='100'a='tail -1 /opt/text.txt' | sed -n '1p'i='tail -1 /opt/text1.txt' | sed -n '1p'echo "$IP" >> /opt/text.txtecho "$IP" >> /opt/text1.txtif [[ $a -le $L ]]thenmail -s 'yanchi' 邮箱 < ar/log/boot.logelif [[ $a -ge $L ]];thenmail -s 'huifu' 邮箱 < ar/log/boot.logelseecho "ok"fi~我是想把这个延迟数写进一个文件里进行对比 延迟是会报 但是正常后不报 ,而且正常情况下运行还会发送 谁能帮忙看看

回答2:

希望能好用。