请大侠看一下,grep:write error:Broken pipe错误,是怎么回事

如题所述

涉及到grep的,就只有这段了。全部代码如下:

#!/bin/sh
echo "---------traceroute begin-----------"

i=$# #get the number of parameters

if [ $i -eq 0 ];then #if no paramter, exit
exit 1
fi

eval destip='$'$i
result=$destip
traceroute $destip > $result

if [ ! -f $result ]; then #if no result, exit
echo fail
# rm $result
exit 1
fi

i=1 #current ip
row=1 #current row
all=`cat $result | wc -l` #the rows of file result
ipresult=0 #one ip's result, 0 is fail,1 is success

while [ $i -le $# ];do #all ip address would be checked
eval ip='$'$i #get the ip address
ipresult=0
while [ $row -le $all ];do
sum=`sed -n "$row,$row p" $result | grep $ip | grep -v X -c`
row=`expr $row + 1`

if [ $sum -eq 0 ];then
continue
else
ipresult=1
break
fi
done
if [ $ipresult -eq 0 ];then #cannot find the record, then fail, exit
echo fail
# rm $result
exit 1
else #found the record, then go on the next ip address
i=`expr $i + 1`
fi
done

echo "---------traceroute end ------------"
echo success
#rm $result
exit 0
温馨提示:答案为网友推荐,仅供参考
相似回答