CentOS详细安装之十六:Linux的简单shell脚本-检查网络状态并email报警

#!/bin/sh
ping -c 5 192.168.1.111 >> state.txt 
file="state.txt"
flag=0
for line in `cat $file | grep "100% packet loss"`
do
flag=1
done 
echo $flag
if [ $flag == 1 ];then
echo $flag
rm -rf state.txt
echo "192.168.1.111:连接不正常" | mutt -s "192.168.1.111:服务器报警" [email protected]
fi

#具体mutt发邮件请见上一章节

相关推荐