Monday, 21 December 2009

tcl scripting

As i've now got Dynamips working on my MacBook, and my BSCI, BCMSN, and ONT Lab Portfolio arrived today, i've started taking a look at BSCI (for no other reason than it is Router-focused, i'll actually probably take this exam last..).

First thing I want to make notes on; tcl scripts.

Say you have just set-up a routing domain (EIGRP, OSPF, IS-IS, anything), and now would like to verify that you can reach each of the devices with a simply ICMP Ping. You could sit there and enter ping 1.1.1.1, ping 2.2.2.2, ping 3.3.3.3 etc etc, OR you could use a tcl script.

N.B. Cisco suggest writing your tcl script in a Notepad window, and then paste it into the router. Useful if you need the same script from multiple devices. You can use Notepad in the CCIE Lab.

To create a script to ping 10.1.1.1, 10.1.2.1, 10.1.3.1;

R1>
R1>enable
R1#tclsh
R1(tcl)#foreach address {
+>(tcl)#10.1.1.1
+>(tcl)#10.1.2.1
+>(tcl)#10.1.3.1
+>(tcl)#} {
+>(tcl)#ping $address
+>(tcl)# }

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/8 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.2.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/7/12 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.3.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/4 ms
R1(tcl)#tclquit
R1#

You must be in enable mode to use the tcl shell.

tclsh takes you into the tcl shell mode - notice the prompt changes!

The command foreach $address { starts a list of devices to which you want to do the command.

You can then list your devices, one on each line.

Close the list with a closing brace }, then open a new brace {

Now enter your ping command followed by $address to call the previous list.

You need to have a space before the final closing brace }. Once you press enter after the final brace, the commands will run.

To exit the tcl shell, you enter tclquit.

No comments:

Post a Comment