TCL scripting

Unanswered Question
Jun 7th, 2007

Hi, could someone please explain the following script to me? And also, how could I edit it so it just showed dialer interfaces? I have read about regular expressions but I find them quite confusing.

Thanks in advance.

proc get_ints {} {

#puts "BEFORE\n"

set check ""

set int_out [ exec "show interfaces\n" ]

puts $int_out

puts ""

set mylist [regexp -all -nocase -line -inline {(^[a-z]*[0-9]/*[0-9]*/*[0-9]*)} $int_out]

#puts "MYLIST $mylist\n"

foreach int $mylist {

#puts "INT $int\n"

if {![string equal $check $int]} {

if {[info exists ints_out]} {

append ints_out ", " $int

} else {

set ints_out $int


set check $int



#puts "AFTER\n"

return $ints_out


puts ""

puts [eval get_ints]

I have this problem too.
0 votes
  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 4.7 (4 ratings)
Joe Clarke Thu, 06/07/2007 - 05:57

proc get_ints {match } {

set output [exec "show interfaces"]

set intlist [regexp -all -line -inline "^$match\[\\d\\./:]+" $output]

return [join $intlist ","]


puts ""

puts [get_ints "Dialer"]

Joe Clarke Sat, 06/09/2007 - 14:49

FYI, this script calls a TCL proc called "get_ints" with a single argument. The argument specifies the interface pattern you wish to match ("Dialer" in this case). The get_ints proc executes a "show interfaces" command, and goes through the output searching for lines that begin with the desired match pattern followed by one or more digit, period, forward slash, or colon. The resulting list of matching interfaces is then joined together with commas, and returned to the caller which then prints the list out to the controlling terminal.

The end result will be a list of Dialer interfaces on this device.

voiper_99 Tue, 06/12/2007 - 17:43

I tried the above script but received the following error:

no value given for parameter "match" to "get_ints"

I tried adding a "set match dialer" line but this did not work.

Joe Clarke Tue, 06/12/2007 - 19:56

You need to call the get_ints proc with a parameter indicating the interface pattern you wish to match. If you pasted the script exactly how I wrote it, you should get a list of Dialer interfaces on the device. If you wanted a list of FastEthernet interfaces:

puts [get_ints "FastEthernet"]

voiper_99 Tue, 06/12/2007 - 20:34

ahh OK then.

I just have one more question (for now anyway) :P

I have successfully created an if statement that only accepts a number between 1 and 8, if I try to enter the number 9 it will repeat the question again, however, if I enter a letter I get the following message:

"can't use non-numeric string as operand of "+""

Is it possible to further restrict my if statement so that if a letter is entered the question will repeat itself until a valid number is entered? I know I can use the "or" || but is it possible to "or" a-z instead of one letter at a time?

Joe Clarke Tue, 06/12/2007 - 20:48

set done 0

while { ! $done } {

puts -nonewline "Enter value (1 - 8) : "

flush stdout

gets stdin response

if { [string is digit -strict $response] && $response > 0 && $response < 9 } {

set done 1



voiper_99 Sun, 06/17/2007 - 00:31

I have successfully completed my script and it works perfectly, however, I have two small issues.

The first is that the router will crash if I press crtl+shift+6, and seeing as though I am not the only person that will be using the router that I have put the script on it would be good if I could stop this from occurring. Is there a way to prevent this from happening?

The second issue I am having is that if more than one person uses the script at a time on the one router the script will crash.

As stated above I am very new to TCL scripting so please bare with me if these are simple questions. Thank you.

Joe Clarke Sun, 06/17/2007 - 09:16

Please provide a show stack after the crash, the script, and exactly what you mean when you say the script crashes.


This Discussion