Search

Wednesday, August 5, 2015

TCL Script with Brief Explanation - Cisco IOS - Darby Weaver

TCL Script with Brief Explanation - Cisco IOS - Darby Weaver

We use TCL Scripts to test our end to end connectivity in our racks or pods.  Here's an example in case some needs it.

tclsh -> Allows us to enter the TCL shell to enter our commands, in this case we are going to declare our variables and then tell the TCL shell what to do with each of them, in this case "ping $addr" and then quit the action by using tclquit and finally after the actions are completed the command "exit" will allow us to leave the TCL shell and return to the IOS CLI.

foreach -> The action we are going to perform per variable declared.

addr -> The variable name (We could use "IP" for example and then at the end of the declaration we would then use "ping $IP" to illicit a ping command "for each" "IP" that we declared.

Note: We can add variable to the ping command like repeat xxx or others just as we would at the IOS CLI.

We type this into notepad and then copy and paste into the CLI.

We obtain these IP's by performing the command:

Perform a "show ip alias: on each router or switch and then remove the subnet information.  It's actually a pretty clean action.  Try it.  Or just do it the long way... your choice.

tclsh
foreach addr {
1.1.1.1
172.10.124.129
172.10.101.1
172.10.124.130
172.10.23.2
172.10.102.1
172.10.25.97
172.10.25.93
172.10.25.89
172.10.23.100
172.10.32.3
172.10.43.3
172.10.23.3
172.10.103.1
4.4.4.4
172.10.124.131
172.10.43.4
172.10.104.1
} {ping $addr}
Tclquit


When you copy into the IOS CLI, it looks like this:

R1#tclsh
R1(tcl)#foreach addr {
+>(tcl)#1.1.1.1
+>(tcl)#172.10.124.129
+>(tcl)#172.10.101.1
+>(tcl)#172.10.124.130
+>(tcl)#172.10.23.2
+>(tcl)#172.10.102.1
+>(tcl)#172.10.25.97
+>(tcl)#172.10.25.93
+>(tcl)#172.10.25.89
+>(tcl)#172.10.23.100
+>(tcl)#172.10.32.3
+>(tcl)#172.10.43.3
+>(tcl)#172.10.23.3
+>(tcl)#172.10.103.1
+>(tcl)#4.4.4.4
+>(tcl)#172.10.124.131
+>(tcl)#172.10.43.4
+>(tcl)#172.10.104.1
+>(tcl)#} {ping $addr}
Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/5 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.10.124.129, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/5 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.10.101.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/5 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.10.124.130, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/5 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.10.23.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 3/4/5 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.10.102.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/5 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.10.25.97, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/5 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.10.25.93, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/5 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.10.25.89, 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 172.10.23.100, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/5 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.10.32.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 172.10.43.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 172.10.23.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 172.10.103.1, 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 4.4.4.4, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 5/8/9 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.10.124.131, timeout is 2 seconds:
.!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/5/6 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.10.43.4, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 8/8/9 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.10.104.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 8/9/12 ms
R1(tcl)#exit
R1#


If you time out you'll find your issues quickly.  I usually repeat with a value of 2 versus 5 pings per device, which typically allows for ARP resolution and is lightening fast too.  Your choice, the default is a value of 5 as seen above "5/5".

Hope this helps!

Thanks

Darby Weaver

http://www.darbyslogs.blogspot.com

No comments: