本帖最后由 andy 于 2010-2-1 18:59 编辑
#! /bin/bash
N=2
rmail=15810682546@139.com
while :; do
ipfile=/usr/local/sbin/serverip.txt
for ip in `cat $ipfile`; do
mailfile=/tmp/pkgloss.txt
pkgloss=`ping -c4 $ip |grep 'transm' |awk -F',' '{print $2}' |awk '{print $1}'`
if [ $pkgloss -lt $N ]; then
echo $ip >$mailfile
ping -c4 $ip |grep 'transm' >>$mailfile
mail -s "$ip loss packets" $rmail<$mailfile
fi
done
sleep 100
done
#! /bin/bash
N=2
rmail=15810682546@139.com
while :; do
ipfile=/usr/local/sbin/serverip.txt
for ip in `cat $ipfile`; do
mailfile=/tmp/pkgloss.txt
pkgloss=`ping -c4 $ip |grep 'transm' |awk -F',' '{print $2}' |awk '{print $1}'`
if [ $pkgloss -lt $N ]; then
echo $ip >$mailfile
ping -c4 $ip |grep 'transm' >>$mailfile
mail -s "$ip loss packets" $rmail<$mailfile
fi
done
sleep 100
done
0
本帖最后由 andy 于 2010-2-1 18:59 编辑
改进后的脚本:
#! /bin/bash
N=5
rmail=15810682546@139.com
while :; do
ipfile=/usr/local/sbin/serverip.txt
for ip in `cat $ipfile`; do
mailfile=/tmp/pkgloss.txt
echo $ip >$mailfile
ping -c10 $ip |grep 'transm' >>$mailfile
pkgloss=`grep 'transm' $mailfile |awk -F',' '{print $2}' |awk '{print $1}'`
if [ $pkgloss -lt $N ]; then
mail -s "$ip:$pkgloss resieve" $rmail<$mailfile
fi
done
sleep 60
done
改进后的脚本:
#! /bin/bash
N=5
rmail=15810682546@139.com
while :; do
ipfile=/usr/local/sbin/serverip.txt
for ip in `cat $ipfile`; do
mailfile=/tmp/pkgloss.txt
echo $ip >$mailfile
ping -c10 $ip |grep 'transm' >>$mailfile
pkgloss=`grep 'transm' $mailfile |awk -F',' '{print $2}' |awk '{print $1}'`
if [ $pkgloss -lt $N ]; then
mail -s "$ip:$pkgloss resieve" $rmail<$mailfile
fi
done
sleep 60
done
编辑回复