Example: Tcl script with command-line parameters
In a comment to the “Execute multiple commands at once” post, Michal has asked for a complete Tcl-shell-with-parameter example. Here's a short script that shuts down the interface and displays its status:
- Variable ifname is set to the value of the first command-line parameter (in many other programming languages, this would be written as argv[0]);
- If the ifname is empty, the script aborts and prints the usage guidelines (again, in a more human-oriented programming language, this would be if (ifname == “”) ...);
- The show ip interface ifname command is executed. If it fails, the interface name is not correct and the script aborts.
- IOS configuration commands interface ifname and shutdown are executed.
- The show ip interface brief configuration command is executed and filtered with the interface name.
#
# ifname is set to first CLI parameter (interface name)
#
set ifname [lindex $argv 0]
if {[string equal $ifname ""]} { puts "Usage: shutdown ifname"; return; }
if { [ catch { exec "show ip interface $ifname" } errmsg ] } {
puts "Invalid interface $ifname, show ip interface failed"; return}
ios_config "interface $ifname" "shutdown"
puts [ exec "show ip interface brief ¦ include $ifname" ]
If you store this Tcl script into your flash as shutdown.tcl and configure alias exec shutdown tclsh flash:shutdown.tcl, you can execute the command shutdown Serial0 to shut down the serial interface.
Notes:
- The last show command will display the interface status only if the specified interface name exactly matches the actual IOS interface name (whereas the rest of the script accepts shortcut names). The more generic matching algorithm is left as an exercise for the reader
- For more in-depth information on Tclsh implementation on Cisco IOS, read the IOS Tclsh resources.
- This article is part of You've asked for it series.
Or you could change the script. Like any other language, Tcl has loop constructs.
However.. I wanted to do the same thing with an interface of accesspoint..too bad.. This one is not supporting tcl scripts.. :(
So what i was thinking... Is this script easy to edit that it can telnet to the accesspoint and push some cli commands.. Enable,conf t interface dot11radio0,shutdown ???
Thankssss :)
Like service flash:script.tcl ?? That will be great..
I just want to activated some ios commands on this router when i'm calling the dialpeer number :)
So how can i use a tcl script with the ivr applications?
Thanks
I will search further.. Thanks anyway for sharing you're knowledge.. :)
What will the script look like if I had to run the following commands:
no aaa accounting network default start-stop group tacacs+
no aaa accounting resource default stop-failure group tacacs+
This is just an example....