Running tclsh Scripts

Articles » Running tclsh Scripts

Tcl shell (started with the tclsh Cisco IOS CLI command) was introduced in Cisco IOS release 12.3(2)T. The Tcl shell can be used to execute interactive Tcl commands interspersed with regular Cisco IOS CLI commands. It can also be used to run Tcl scripts that can substantially enhance the Cisco IOS CLI experience.

Due to security considerations, primarily the ability to write IOS-based password grabbers, the tclsh command is available only in CLI privilege level 15.

Running tclsh Scripts

Cisco IOS tclsh implementation behaves similarly to the tclsh implementations on other operating systems. The tclsh command without parameters starts the interactive shell. When one or more parameters are present in the tclsh command, the first parameter represents the name of the Tcl script to execute and the remaining parameters are passed to the script.

The first parameter of the Cisco IOS tclsh command is an Integrated File System (IFS) URL that can point to a local file (for example flash:myScript.tcl or nvram:script.tcl) or a file accessible through any of the remote file access methods available in Cisco IOS (TFTP, FTP, RCP, SCP, HTTP or HTTPS).

Example

Store a simple helloWorld.tcl file on an external TFTP server with the IP address 10.0.0.10.

helloWorld.tcl
puts "hello world" 

Executing the command tclsh tftp://10.0.0.10/helloWorld.tcl on a router that can reach the TFTP server will result in the “famous” hello world printout:

Router#tclsh tftp://10.0.0.10/helloWorld.tcl
Loading helloWorld.tcl from 10.0.0.10 (via FastEthernet0/0): !
[OK - 20 bytes]
hello, world

For more details read Cisco IOS XE Scripting with Tcl.

This article written by Ivan Pepelnjak in 2007 was originally published on CT3 wiki which became unreachable in early 2019. The text was retrieved from an Internet Archive snapshot and republished on ipSpace.net
Sidebar