TCL Script

From: Nadeem Zahid \(iszahid\) (iszahid@cisco.com)
Date: Tue Dec 13 2005 - 21:47:49 GMT-3


I have written this script that frees you from copy past the sh ip alias
output from each router to a separate notepad
and extracting the ip addresses and then pasting into another script. It
does it all for you - if you can remember it...!
Just copy/past at each console

set ip {}
set add {}
set output [sh ip alias]
foreach line [split $output \r\n] {
if {[regexp "Interface" $line]} {
set ip [lindex $line 1]
lappend add $ip
puts $ip}
}
foreach ip $add {ping $ip}

* If first time it eats words while pasting - try one more time.

Output:
=====

Rack02R3(tcl)#set output [sh ip alias]
Address Type IP Address Port
Interface 148.1.3.3
Interface 148.1.0.3
Interface 150.1.3.3
Interface 148.1.35.3
Interface 192.10.1.3
Rack02R3(tcl)#foreach line [split $output \r\n] {
+>if {[regexp "Interface" $line]} {
+>set ip [lindex $line 1]
+>lappend add $ip
+>puts $ip}
+>}
148.1.3.3
148.1.0.3
150.1.3.3
148.1.35.3
192.10.1.3

Rack02R3(tcl)#foreach ip $add {ping $ip}

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 148.1.3.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 148.1.0.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/5/8 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 150.1.3.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/4 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 148.1.35.3, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.10.1.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/4 ms

Nadeem



This archive was generated by hypermail 2.1.4 : Mon Jan 09 2006 - 07:07:51 GMT-3