All
Please help, i will telnet to router to obain the ping status and compare, if higher than normal latency, i will have further action..
if i do the telent and in perl script then ....
e.g the result i obtain from the router will be =' Success rate is 100 percent (5/5), round-trip min/avg/max = 140/140/141 ms'
and the xxxx/140/xxxx ms , while i only concern the average one = 140ms. How can I read the value in the middle of the '/'line, sometimes will be 2 digit , sometimes will be 4 digit and how I can compare it?
For example I define 180ms is not acceptable, if now the ping is 100/250/300 ms while the 250 is higher than 180 , then I will print 'high Alarm'.
MSG="Success rate is 100 percent (5/5), round-trip min/avg/max = 140/140/141 ms"
AVG=`echo "$MSG" | cut -f2 -d= | cut -f2 -d/`
if [ "$AVG" -gt 180 ]
then
echo "Alarm!"
fi
Thanks for robotronic 's help.
but i was mistake the result i obtain from the router must be look like this
"Router#ping 192.168.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 104/104/104 ms
Router#"
there must be 7 lines how can i get the middle average value
in addition, how i can handle the non standard reply , (e.g the remote cannot be ping)
Router#ping 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
U.U..
Success rate is 0 percent (0/5)
Router#
anyway, thanks for robotronic 's help as I had already search for a very long time for nothing.
Populate the MSG variable with the text you want or substitute the echo command with the output of telnet (through pipe) and then:
echo "$MSG" | awk -F= '
/round-trip/ {
split($2, a, "/");
avg=a[2];
if (avg > 180) {
print("Alarm! ("avg")");
} else {
print("Ping OK. ("avg")");
}
flag=1;
exit;
}
END {
if (! flag) {
print("Cannot ping!");
}
}
'
or, continuing with the shell way:
AVG=`echo "$MSG" | grep "round-trip" | cut -f2 -d= | cut -f2 -d/`
if [ ! "$AVG" ]
then
echo "Cannot ping!"
elif [ "$AVG" -gt 180 ]
then
echo "Alarm! ($AVG)"
else
echo "Ping OK. ($AVG)"
fi
robotronic
I am trying, and sol glad got your reply.
I will try after office hour.