Placed

Automate Repetitive Tasks Using TcL Scripts

Posted by: admin  :  Category: CCIE, CCNA, CCNP, Routing, Switching




 

TcL-Scripting

The Cisco IOS Tcl shell was designed to allow users to run Tcl commands directly from the Cisco IOS CLI prompt. Cisco IOS software does contain some subsystems such as Embedded Syslog Manager (ESM) and Interactive Voice Response (IVR) that use Tcl interpreters as part of their implementation. These subsystems have their own proprietary commands and keyword options that are not available in the Tcl shell.

The Tcl shell can be used to run Cisco IOS CLI EXEC commands within a Tcl script. Using the Tcl shell to run CLI commands allows users to to automate repetitive tasks, and to create custom output for show commands.

Creating and Execute a Tcl Script:

a. Open a text editor and create a new text file. Using a text file saves time, especially if you are pasting the Tcl script into multiple devices.

b. Start with the tclsh command to enter Tcl shell mode in which you can use native Tcl instructions like foreach or issue EXEC mode commands. You can also access configuration mode from within the Tcl shell and issue configuration commands from their respective menus, although these features are not explored in this lab.

R1# tclsh
R1(tcl)#

c. Begin a loop using the foreach instruction. The loop iterates over a sequence of values, executing a defined sequence of instructions once for each value. Think of it as “for each value in Values, do each instruction in Instructions.” For each iteration of the loop, $identifier reflects the current value in Values. The foreach instruction uses the following model.

foreach identifier {
value1
value2
.
.
.
valueX
} {
instruction1
instruction2
.
.
.
instructionY
}

d. To create a Tcl script that pings every IP address in the topology, enter each IP address in the value list. Issue the ping $address command as the only instruction in the instruction list.

foreach address {
10.1.1.1
10.1.2.1
10.1.3.1
10.1.4.1
10.100.12.1
10.2.1.1
10.2.2.1
10.2.3.1
10.2.4.1
10.100.12.2
} {
ping $address
}

e. Enter Tcl mode with the tclsh command, and copy the Tcl script from the text file and paste it into R1.

R1# tclsh
R1(tcl)#foreach address {
+>(tcl)#10.1.1.1
+>(tcl)#10.1.2.1
+>(tcl)#10.1.3.1
+>(tcl)#10.1.4.1
+>(tcl)#10.100.12.1
+>(tcl)#10.2.1.1
+>(tcl)#10.2.2.1
+>(tcl)#10.2.3.1
+>(tcl)#10.2.4.1
+>(tcl)#10.100.12.2
+>(tcl)#} {
+>(tcl)#ping $address
+>(tcl)#}

Note: You might need to press Enter to execute the script.

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/1/4 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 = 1/1/4 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/1/4 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.4.1, 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 10.100.12.1, timeout is 2 seconds:
…..
Success rate is 0 percent (0/5)
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.2.1.1, timeout is 2 seconds:
…..
Success rate is 0 percent (0/5)
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.2.2.1, timeout is 2 seconds:
…..
Success rate is 0 percent (0/5)
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.2.3.1, timeout is 2 seconds:
…..
Success rate is 0 percent (0/5)
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.2.4.1, timeout is 2 seconds:
…..
Success rate is 0 percent (0/5)
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.100.12.2, timeout is 2 seconds:
…..
Success rate is 0 percent (0/5)

g. Exit Tcl mode using the tclquit command on each device.

R1(tcl)#tclquit

Note: You can also use the exit command to exit Tcl mode.

Conclusion:
The creation of Tcl scripts takes a little extra time initially but can save considerable time during testing each time the script is executed. Use Tcl scripts to verify all your configurations in this course. If you verify your work, both academically and in production networks, you will gain knowledge and save time in troubleshooting.

Search for Additional Labs: [adsense_id=”6″]

  TcL-Sripting (2,670 hits)

  Packet Tracer 5-3-3 by Cisco (48.3 MiB, 3,580 hits)
You do not have permission to download this file.

Also check out these other assume training resources:


One Response to “Automate Repetitive Tasks Using TcL Scripts”

  1. reza Says:

    very good

Leave a Reply

What is 13 + 6 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)

*

http://s51.sitemeter.com/meter.asp?site=s51ciscolab Site Meter