TCL (Tool Command Language) is a useful IOS and IOS.XE feature enabling you to run scripts from the Cisco Command Line Interface (CLI). These scripts are sometimes referred to as “tickle” scripts.
Cisco have a guide here
The ability to run scripts can be really useful. For example, you can change an IP address on an interface without losing connectivity halfway through.
The following is a simple example that pings a number of IP addresses in sequence:
tclsh
foreach ip {
1.1.1.1
2.2.2.2
3.3.3.3
4.4.4.4
5.5.5.5
} {ping $ip }
tclquit
Note that “ip” is a variable name, and can be any character string. You can obviously add as many IP addresses as you like. Here’s an example of the script in use:
R1#tclsh
R1(tcl)#foreach ip {
+>(tcl)#
+>(tcl)#1.1.1.1
+>(tcl)#2.2.2.2
+>(tcl)#3.3.3.3
+>(tcl)#4.4.4.4
+>(tcl)#5.5.5.5
+>(tcl)#
+>(tcl)#} {ping $ip }
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/5/8 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 40/56/84 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 48/63/88 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 = 44/62/88 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 5.5.5.5, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/7/8 ms
R1(tcl)#tclquit
R1#
Another example writes the same script to flash, enabling you to recall it again later.
tclsh
puts [open "flash:my-tcl-script.tcl" w+] {
foreach ip {
1.1.1.1
2.2.2.2
3.3.3.3
4.4.4.4
5.5.5.5
} {ping $ip }
}
tclquit
You can then see the script stored in flash:
Directory of flash:/
1 -rw- 55871496 Jan 12 2015 08:45:28 +00:00 c800-universalk9-mz.SPA.153-2.T.bin
2 -rw- 660 Sep 28 2021 18:28:12 +01:00 vlan.dat
3 -rw- 71 Jun 30 2023 20:57:04 +01:00 my-tcl-script.tcl
The script would then be executed as follows:
tclsh flash:my-tcl-script.tcl R1#tclsh flash:my-tcl-script.tcl 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 = 8/11/12 ms Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds: !!!!! etc
The following example enables you to change the IP on an interface without losing connectivity halfway through
tclsh
puts [open "flash:ip-change.tcl" w+] {
##
## IP change Script
##
ios_config "interface gigabitEthernet 0" "ip address 10.10.10.10 255.255.255.240"
}
tclquit
The script would then be executed as follows:
tclsh flash:/ip-change.tcl R1#show run int gigabitEthernet 0 Building configuration... Current configuration : 59 bytes ! interface GigabitEthernet0 ip address 10.10.10.10 255.255.255.240 end