Running Tcl procedures from command line

Starting in IOS release 12.3(2)T, Tcl shell is accessible from the command line interface with the tclsh command. After entering this command, you get the Router(tcl)# prompt and can enter individual Tcl commands (the help is confusing, though - you get help on exec-mode commands, but none of them work).

What the documentation fails to tell you, though, is that you can specify a file name (actually an IFS URL) as the parameter to the tclsh command to execute the Tcl commands in that file. The file can be local (stored in flash or even NVRAM) or remote, in which case the router downloads the file and executes it.For example, if you store a simple helloWorld.tcl file ...

puts "hello world";
... on an external TFTP server and execute it with the tclsh tftp://10.0.0.10/helloWorld.tcl command, you'll get the "famous" 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

An revised version of this article is available in the CT3 wiki.

You can find more Tclsh-related information in the Tclsh on Cisco IOS tutorial. Sample Tclsh scripts are available in the Tclsh script library. If you need expert help in planning, developing or deploying Tclsh scripts in your network, contact the author.

2 comments:

  1. do you now how to pass a script as a argument?
    i need somethig like
    tclsh "wait 5000"

    ReplyDelete
  2. Ivan Pepelnjak26 April, 2010 20:37

    Worst case: write a Tclsh script that executes its first argument.

    ReplyDelete

You don't have to log in to post a comment, but please do provide your real name/URL. Anonymous comments might get deleted.

Ivan Pepelnjak, CCIE#1354, is the chief technology advisor for NIL Data Communications. He has been designing and implementing large-scale data communications networks as well as teaching and writing books about advanced technologies since 1990. See his full profile, contact him or follow @ioshints on Twitter.