Learning how to run a TCL script beyond my first posting was an interesting journey. Falling back to my iOS days, I tried finding some of the commands by using our old friend ? and wasn’t finding the commands. I didn’t have a lot of luck in finding the commands based on the response I got compared to what IOS would normally report. Apparently the commands are either “hidden” or response for ? isn’t in tclsh interpreter.
Before getting started, execute the tclsh command. Once you are at the tcl prompt, type info patchlevel. You should get a version back of at least 8.3.4. What I am showing you here is based on that version number being present on the router. If for some reason, you get an earlier version, you will probably need to upgrade the version of IOS on the router for this to work.
Here is a script file that I put together to do a basic job of documenting a router –
set output [exec “dir”]
set output [exec “sh ip int br”]
set output [exec “sh run”]
This script will do a basic job of documenting a router. As you can see from the commands listed here, it will list all the files in the routers flash, all interfaces (active or not) and the currently running config of the router without pagination. Here is where things get a little interesting, if you save the above commands to a text file and upload it to the router, you are one step closer to being able to run the script from the router without pasting the file into a terminal session.
I would save the above commands into a text file and upload to the router. I would rename the file to have a .tcl extension to make it standout as a command file to be used with the tclsh command. In global config mode, I enter the following command –
alias exec document tclsh flash:doc.tcl
All you have to do at this point is to type doc from the enable prompt and press Enter. All three commands will then execute, one at a time. As I understand from what I have read so far, the set command sets up the command to run and the puts command displays the info to the screen. From some other commands I have seen reference to, it may be possible to automatically redirect output to a tftp server and using the IOS KRON command to automatically have this command run at a certain time every day or at a interval that you specify. That will be a subject for another post.