cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1248
Views
5
Helpful
3
Replies

TCL Script to print Router-ID of every neighbor on a certain interface

astoffel1
Level 1
Level 1
This code will do more than print but I am just taking the first steps.
 
if [catch {cli_exec $cli1(fd) "enable"} _cli_result] {
    error $_cli_result $errorInfo
}
if [catch {cli_exec $cli1(fd) "show ip ospf neighbor gigabitEthernet 0/0 detail | include Neighbor 10."} _cli_result] {
error $_cli_result $errorInfo
}
 
set _ospf_neighbors [regexp { Neighbor ([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)} "$_cli_result" match 1st_8et 2nd_8et 3rd_8et 4th_8et]
 
action_syslog msg $1st_8et.$2nd_8et.$3rd_8et.$4th_8et
 
 

 Right now my output only gives the first router-id, any idea how I would print 2 or more router-ids?

1 Accepted Solution

Accepted Solutions

Joe Clarke
Cisco Employee
Cisco Employee

You can iterate over the lines:

 

foreach line [split $_cli_result "\n"] {

   set _ospf_neighbors [regexp { Neighbor ([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)} "$line" match 1st_8et 2nd_8et 3rd_8et 4th_8et]

   ...

}

View solution in original post

3 Replies 3

Joe Clarke
Cisco Employee
Cisco Employee

You can iterate over the lines:

 

foreach line [split $_cli_result "\n"] {

   set _ospf_neighbors [regexp { Neighbor ([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)} "$line" match 1st_8et 2nd_8et 3rd_8et 4th_8et]

   ...

}

Thank you very much Joseph, you are the MVP for TCL. Just started using it, been poking around the forums here for some example seems like you always point people in the right direction.

 

My question is any documentation you would recommend ?

I recommend any general Tcl site (like tcl.tk) or book to learn the language.  We use standard Tcl 8.3.4, so getting a solid foundation in Tcl will help.  Besides the Cisco.com docs on "EEM Tcl" that you can find with Google, have a look at https://supportforums.cisco.com/document/48891/cisco-eem-best-practices .  That will provide much more insight into the capabilities of EEM.