解答:
#!/bin/bash
rmail=12345@qq.com
export LANG=zh_CN.UTF-8
ping -c50 192.168.1.10 >/tmp/ping.txt
if [ "$?" != "0" ]; then
echo "`date +"%Y-%m-%d %H:%M:%S"` IP地址:192.168.1.10 网络不通,请检查网络!" >>/tmp/pkgloss.txt
mail -s "测试IP网络异常报警" $rmailfi
loss1=`cat /tmp/ping.txt |grep loss|awk '{print $6}'|awk -F% '{print $1}'`
if [ $loss1 -gt 40 ]; then
echo "`date +"%Y-%m-%d %H:%M:%S"` IP地址:192.168.1.10 丢包率超过40" >>/tmp/pkgloss.txt
mail -s "测试IP网络异常报警" $rmailfi
if [ $loss1 -gt 80 ]; then
echo "`date +"%Y-%m-%d %H:%M:%S"` IP地址:192.168.1.10 丢包率超过80" >>/tmp/pkgloss.txt
mail -s "测试IP网络异常报警" $rmailfi
echo "" >/tmp/pkgloss.txt: