Cisco TCL multiple commands at once

Built-in into IOS, TCL interpreter can be useful in several scenarios.

You may need to apply several commands on a Cisco device when some of the earlier commands can prevent later commands to be delivered. For example, one may need to move an external interface of a remote router to a different VRF. The moment the command that changes VRF delivered, the router removes IP address on the interface and the interactive terminal will not be able to send the remaining commands.

To avoid a lockout, prior to applying the configuration, save the configuration and enter the “reload in 10″ exec command, which will restart the router in 10 minutes unless canceled. Don’t forget to do “reload cancel” once you are happy with the outcome.

The following example shows how to enter interface configuration mode and change its description.

ROUTER#tclsh
ROUTER(tcl)#ios_config “interface GigabitEthernet2” “description WAN Interface”

Instead of using an interactive interpreter, one can create a script file and save it on the flash to be later invoked.

flash:/script.tcl file content:
ios_config “interface GigabitEthernet1” “description LAN Interface”

To execute this file, pass it as an argument to tclsh command:

ROUTER#tclsh
ROUTER(tcl)#tclsh flash:/script.tcl

To upload script files to the router’s flash memory use one of the protocols that router supports, such as TFTP. If such access is not available, one can use puts function of TCL that writes the list of strings into a text file.

ROUTER#tclsh
ROUTER(tcl)#puts [open “flash:script.tcl” w+] {interface GigabitEthernet2
description WAN}


Note that there is no Enter after the first curly brace.