Building Network Automation Solutions
6 week online course starting in September 2017

Executing IOS commands from Tcl shell

The Tcl procedures used to execute IOS commands in Embedded Event Manager (cli_open, cli_write ...) don't work when you start Tcl shell from command line interface. To execute IOS commands in this context, use:

  • exec command to execute an exec-level command, for example exec "show ip route"
  • ios_config mode command to configure the router
If the first parameter of the ios_config command is a global configuration command, you shall omit the second parameter (for example, ios_config "hostname router"). To configure a parameter in one of the sub-configuration modes (for example, interface state), use the first parameter to specify the configuration mode and the second parameter as the actual configuration command (for example, ios_config "interface loop 0" "no shutdown"). And if you want to configure BGP neighbor in VRF address family within the BGP routing process ... then you're out of luck, you can't do it with Tcl shell you just keep adding parameters (undocumented!) to the ios_config command. You can even perform several configuration tasks in one go, for example ios_config "interface loopback 111" "ip address" "description Test" "ip ospf cost 20".

Note: I knew what I wrote initially did not feel right (although that's what the docs say), so I simply had to go back and so some more testing.

An in-depth 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.


Post a Comment

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