Search This Blog & Internet

Wednesday, April 27, 2011

TCL within CiscoWorks

I wrote the following script which shut down the unused interfaces (status "down") on Catalyst 2960. When I copied and pasted the script via SSH, it was working fine without any error message, but when I executed it via CiscoWorks (RME 4.3.1) the job failed with the following error message:

tclsh
Switch(tcl)#
for {set x 0} {$x<24} {incr x} {
missing  close-brace
Switch(tcl)#
set etat [string range [lrange [exec sh ip int  brief | i FastEthernet0/$x] 4 4] 0 4 ]
can't read "x": no such variable 
Switch(tcl)#
if { [string equal $etat "down"] } {
missing close-brace 
Switch(tcl)#
puts [ios_config "Interface FastEthernet0/$x"  "shut"]
can't read "x": no such variable
Switch(tcl)#
}
invalid  command name "}"
}
^
% Invalid input detected at '^' marker.

Switch(tcl)#
}
invalid command name "}"
}
^
% Invalid  input detected at '^' marker.

I was wondering why I was getting "missing close-brace" error message!

The reason is that when you type in the script line-by-line like this, you get intermediate prompts requesting additional block data. LMS cannot programmatically handle those prompts. Instead, you need to try converting your script to a single line:

for {set x 0} {$x<24} {incr x} { set etat [string range [lrange 
[exec sh ip int  brief | i FastEthernet0/$x] 4 4] 0 4 ] ; if { 
[string equal $etat "down"] } { puts [ios_config "Interface 
FastEthernet0/$x"  "shut"] } }

No comments:

Post a Comment