cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
140
Views
0
Helpful
0
Replies

TCL if conditions ends a script remaining in tclsh

keith.bennett
Level 1
Level 1

I'm trying to run a tcl script (via automation or pasting into vty.  The commands all individually work but if I try to push it all out, it stops feeding the commands after the first "if" conditional command.

I'm basically trying to rewrite a couple of interface descriptions based on whether there is a port that is line & protocol "up", as that interface is reserved for a FW connection. If 1/0/36 is up/up, rewrite a couple of descriptions. if not up/up, commands will be ignored and move on to the next set of commands.

tclsh
set swhostname [exec sh run | inc hostname]
regexp {(\w*)\-(\w\w)\-sw-A} $swhostname match location_id floor
set FWexist [exec sh int desc | inc Gi1/0/36]
regexp {Gi1\/0\/36\s+(up)\s+(up)} $FWexist match 36line 36protocol

if { $36line == "up" && $36protocol == "up" } {set fwname $location_id-$floor-FW-A}
## The above commands run and the first "if" provides the expected output, but nothing below runs.
if { $36line == "up" && $36protocol == "up" } {ios_config "int gig1/0/36" "description NTW|$fwname|wan1|V2"}
if { $36line == "up" && $36protocol == "up" } {ios_config "int gig1/0/37" "description NTW|$fwname|wan2|V200"}
#
set int35desc [exec sh run int gig1/0/35 | inc desc]
set int35upup [exec sh int desc | inc Gi1/0/35]
set int35trunk [exec sh int status | inc Gi1/0/35]
regexp {\w*\-\w\w\-FW-A} $int35desc fwnameconfirm
regexp {connected\s+(\w\w\w\w\w)} $int35trunk fw35trunk
if {$int35desc=="SW-FW/V1"} {set $fwnameconfirm}
regexp {Gi1\/0\/35\s+(up)\s+(up)} $int35upup match 35line 35protocol
##if {$fwnameconfirm == $fwname} {set fwlan1description "description NTW|$fwname|lan1|V1"}
##if {$fwnameconfirm == $fwname && $35line == "up" && $35protocol == "up"} {ios_config "int gig1/0/35" "description NTW|$fwname|lan1|V1"}
if {$fw35trunk == "trunk"&& $35line == "up" && $35protocol == "up"} {ios_config "int gig1/0/35" "description NTW|$fwname|lan1|V1"}
}
exec sho int desc | i FW
##more commands follow
tclquit

0 Replies 0

Review Cisco Networking for a $25 gift card