The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Linux behind a cisco router tmm IP Networking 0 01-30-2008 02:54 AM
Cisco Router command to get hostname rahulrathod UNIX for Advanced & Expert Users 3 02-15-2006 09:34 AM
I can't ping my linksys router from Ultra 10 cstovall SUN Solaris 3 01-05-2005 11:47 AM
cannot ping router from sgi irix eidde IP Networking 0 05-14-2004 04:24 PM
ping and telnet macdonto IP Networking 5 10-05-2001 09:24 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-23-2007
optimus optimus is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 3
Perl telnet to cisco router and compare the ping ms

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'.
  #2 (permalink)  
Old 08-23-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Code:
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
  #3 (permalink)  
Old 08-23-2007
optimus optimus is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 3
robotronic thanks ...

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.

Last edited by optimus; 08-23-2007 at 02:59 PM..
  #4 (permalink)  
Old 08-24-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Populate the MSG variable with the text you want or substitute the echo command with the output of telnet (through pipe) and then:

Code:
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:

Code:
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
  #5 (permalink)  
Old 08-27-2007
optimus optimus is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 3
thanks for robotronic 's reply

robotronic
I am trying, and sol glad got your reply.
I will try after office hour.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0