Options

TCL scripting

chmorinchmorin Member Posts: 1,446 ■■■■■□□□□□
I'm trying to make a script that checked the routers IOS version, and compares it to one that the script wants. If it passes, it outputs Success! at the end, else it outputs FAIL!

This is the start of a script I want to make changes to many devices, but I want it to check the IOS version before it runs so I don't run into any discrepancies between configurations.

I put this script into the router:
proc ver {} {
#Predefined Variables
puts "Setting variable b to equal the version required..."
set b "Cisco IOS Software, 3700 Software (C3745-ADVENTERPRISEK9-M), Version 12.4(12), RELEASE SOFTWARE (fc1)"
puts "Dispalying b:"
puts $b


puts "Setting a to equal the show ver result:"
set a [exec "show ver | inc Cisco IOS Software"]
puts "Displaying a:"
puts $a

puts "Displaying current version..."
puts $a
puts "Displaying Required version..."
puts $b

puts "Checking to see if current version matches needed version..."
if {$a==$b} {puts "Success!"} else {puts "FAIL!"}
}

But for some reason it outputs this:
R1(tcl)#ver
Setting variable b to equal the version required...
Dispalying b:
Cisco IOS Software, 3700 Software (C3745-ADVENTERPRISEK9-M), Version 12.4(12), RELEASE SOFTWARE (fc1)
Setting a to equal the show ver result:
Displaying a:
Cisco IOS Software, 3700 Software (C3745-ADVENTERPRISEK9-M), Version 12.4(12), RELEASE SOFTWARE (fc1)

Displaying current version...
Cisco IOS Software, 3700 Software (C3745-ADVENTERPRISEK9-M), Version 12.4(12), RELEASE SOFTWARE (fc1)

Displaying Required version...
Cisco IOS Software, 3700 Software (C3745-ADVENTERPRISEK9-M), Version 12.4(12), RELEASE SOFTWARE (fc1)
Checking to see if current version matches needed version...
FAIL!

R1(tcl)#

Say I change this code to this, just to test my logic...
proc ver {} {
#Predefined Variables
puts "Setting variable b to equal the version required..."
set b [exec "show ver | inc Cisco IOS Software"]
puts "Dispalying b:"
puts $b


puts "Setting a to equal the show ver result:"
set a [exec "show ver | inc Cisco IOS Software"]
puts "Displaying a:"
puts $a

puts "Displaying current version..."
puts $a
puts "Displaying Required version..."
puts $b

puts "Checking to see if current version matches needed version..."
if {$a==$b} {puts "Success!"} else {puts "FAIL!"}
}

The router displays this:
R1(tcl)#ver
Setting variable b to equal the version required...
Dispalying b:
Cisco IOS Software, 3700 Software (C3745-ADVENTERPRISEK9-M), Version 12.4(12), RELEASE SOFTWARE (fc1)

Setting a to equal the show ver result:
Displaying a:
Cisco IOS Software, 3700 Software (C3745-ADVENTERPRISEK9-M), Version 12.4(12), RELEASE SOFTWARE (fc1)

Displaying current version...
Cisco IOS Software, 3700 Software (C3745-ADVENTERPRISEK9-M), Version 12.4(12), RELEASE SOFTWARE (fc1)

Displaying Required version...
Cisco IOS Software, 3700 Software (C3745-ADVENTERPRISEK9-M), Version 12.4(12), RELEASE SOFTWARE (fc1)

Checking to see if current version matches needed version...
Success!

R1(tcl)#

To me the outputs are identical, but the second one succeeds. To me this means that my
set b "Cisco IOS Software, 3700 Software (C3745-ADVENTERPRISEK9-M), Version 12.4(12), RELEASE SOFTWARE (fc1)"
Is somehow magically not matching the result. I can't find the difference. Any ideas?

EDIT:

I didn't notice it until I previewed this, but when you do "puts" it returns a new line at the end of it. To test if that was the difference, I put \n at the end of my b variable. No dice.
Currently Pursuing
WGU (BS in IT Network Administration) - 52%| CCIE:Voice Written - 0% (0/200 Hours)
mikej412 wrote:
Cisco Networking isn't just a job, it's a Lifestyle.
Sign In or Register to comment.