Perl telnet to cisco router and compare the ping ms


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl telnet to cisco router and compare the ping ms
# 1  
Old 08-23-2007
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  
Old 08-23-2007
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  
Old 08-23-2007
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 03:59 PM..
# 4  
Old 08-24-2007
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  
Old 08-27-2007
thanks for robotronic 's reply

robotronic
I am trying, and sol glad got your reply.
I will try after office hour.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. IP Networking

Need help configuring Cisco 892-k9 router

I bought a Cisco 892-k9 router and I am having in issue trying to setup the initial configuration. Does someone have a sampl configuration for a single subnet that I can use for my configuration? Thanks. (0 Replies)
Discussion started by: gandolf989
0 Replies

2. Shell Programming and Scripting

Perl telnet to router run commands from file

I have a perl script that is called with a router name command list file and output file. The command file can be very large, up to 3k of commands. At first I dumped the command list file to an array and ran the entire file on the router and captured the output. It worked ok for a command list in... (1 Reply)
Discussion started by: numele
1 Replies

3. Shell Programming and Scripting

Perl Telnet cisco routers

Hi all i have little problem finding solution about simple telnet script .... i have 250 routers and on some i have different password and on some they ask just for password no username. So for example 1,2,3 have username and password (user,password) 4, and 5 have different username and password... (0 Replies)
Discussion started by: IvanMP
0 Replies

4. Shell Programming and Scripting

Animation Ping on Solaris Like Cisco Ping

Hi, I develop simple animation ping script on Solaris Platform. It is like Cisco ping. Examples and source code are below. bash-3.00$ gokcell 152.155.180.8 30 Sending 30 Ping Packets to 152.155.180.8 !!!!!!!!!!!!!.!!!!!!!!!!!!!!!. % 93.33 success... % 6.66 packet loss...... (1 Reply)
Discussion started by: gokcell
1 Replies

5. Shell Programming and Scripting

Perl variables inside Net::Telnet::Cisco Module doesn't work

I am writing perl script to configure Cisco device but Variables inside Net::Telnet::Cisco Module doesn't work and passed to device without resolving. Please advise. here is a sample of script: use Net::Telnet::Cisco; $device = "10.14.199.1"; ($o1, $o2, $o3, $o4) = split(/\./,$device);... (5 Replies)
Discussion started by: ahmed_zaher
5 Replies

6. Shell Programming and Scripting

perl telnet issue with cisco

Hi Experts, I am using perl to telnet on cisco boxes. We have this stupid cisco node which does not support "terminal Length0" command. Since I am using Net::Telnet and capturing output with @output = $telnet->cmd('cmd'); Say @output = $telnet->cmd('show version'); Now problem... (2 Replies)
Discussion started by: mtomar
2 Replies

7. IP Networking

isc dhcpd and cisco router

Hello all, I have set up dhcpd on a linux box for serving subnets on multiple vlans configured on a Cisco 6500 with ip helper of the dhcp server. Servers get dhcp leases just fine, however, some machines lose their connection for reboot or what not and I can not get their lease back even though... (0 Replies)
Discussion started by: closedown
0 Replies

8. IP Networking

Linux behind a cisco router

Dear All, I have worked with xDSL routers working in bridged mode, and linux behind them working as a Firewall utilizing IPTABLES. My question is, how this will change if the xDSL router is replaced with a Cisco Router? I mean to ask that, can I assign a public ip on the linux machine, which... (0 Replies)
Discussion started by: tmm
0 Replies

9. UNIX for Advanced & Expert Users

Cisco Router command to get hostname

Hi All, I am connected to a cisco router and I want to know the hostname of this router. I connect as telnet <IPADDRESS> and the prompt shows vpnaccess-bristol> But I want to know the full hostname of the router how can i do that. When i type the hostname command the following... (3 Replies)
Discussion started by: rahulrathod
3 Replies
Login or Register to Ask a Question