Cisco TCL – first steps… Hello world

70px-Tcl-powered.svgFor some time Cisco offers TCL shell on their equipment. This is awesome, because sometimes you need a single command to retrieve information whereas IOS demands you to enter one or more commands.

But before we get lots in possibilities and impossibilities. Lets create a tiny script to say “Hello world”.   First we will write the script afterwards I explain the tricky parts.

R1(tcl)#puts [ open "flash:hworld.tcl" w+ ] {
+>(tcl)#puts "Hello world..."

First I run trough the commands;

Puts is short for PUT String. Output is ‘echoed’ on screen (stdout) unless defined otherwise. Definition is done in brackets. In the first instance a file is opened to which the output is written.

Open opens a file, w+ describes that a file is opened for write AND if no file of that name is found one must be created.

Script can executed by;

R1#tclsh flash:hworld.tcl
Hello world...


If you want to call TCL script more like a IOS command you can create an alias.

R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#alias exec hello tclsh flash:hworld.tcl

An alias name “hello” is created. Once executed you will get the following result.

Hello world...


Okay, writing a tiny tclshell “hello world” script is not rocket-science.
Once you explore more and more you’ll get the hang of it and can do really fun stuff.

This entry was posted in cisco and tagged , . Bookmark the permalink.