- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2015 03:04 PM
So I am starting to write a script that hopefully could be ran on multiple routers at once. The basic changes are Ip address and the minor one I can handle after this problem is solved. The script below is suppose to match by hostname and run the rest of the scipt based on if the hostnames match based on the current router. After running on Router B the output is
" Router B with a Interface address of 200.2.2.0 and a Tunnel ip of 1.1.12.1 and netmask 1.1.11.2"
::cisco::eem::event_register_none
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
if [catch {cli_open} result] {
error $result $errorInfo
} else {
array set cli1 $result
}
array set Router_Info {
Router_A 1.1.1.0 1.1.12.1 1.1.11.2
Router_B 200.2.2.0 99.2.22.1 2.2.22.23
}
if [catch {cli_exec $cli1(fd) "enable"} _cli_result] {
error $_cli_result $errorInfo
}
if [catch {cli_exec $cli1(fd) "show run | inc hostname"} _hostname] {
error $_hostname $errorInfo
}
set _ip_scapper [regexp {hostname ([a-zA-Z0-9_]+)} "$_hostname" match hostname]
action_syslog msg "$hostname"
foreach {Local_Hostname Interface_IP Tunnel_IP NETMASK} [ array get Router_Info] {
action_syslog msg " $Local_Hostname $Interface_IP $Tunnel_IP $NETMASK"
if { $Local_Hostname == $hostname } {
set Interface_IP_Address $Interface_IP
set Tunnel_IP_Address $Tunnel_IP
set NETMASK_IP $NETMASK
break
} else {
}
}
action_syslog msg "$hostname with a Interface address of $Interface_IP_Address and a Tunnel ip of $Tunnel_IP_Address and netmask $NETMASK_IP"
catch {cli_close $cli1(fd) $cli1(tty_id)} result
Solved! Go to Solution.
- Labels:
-
EEM Scripting
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2015 08:18 PM
Arrays can return the elements out of order. List data structure referenced by index can return the data in the order required. Hostname can be captured without opening cli in the script.
set host [info hostname]
set Router_Info [list \
Router_A 1.1.1.0 1.1.12.1 1.1.11.2 \
Router_B 200.2.2.0 99.2.22.1 2.2.22.23 \
]
set element 0
foreach item $Router_Info {
if {[string equal $host $item]} {
puts "[lindex $Router_Info $element] [lindex $Router_Info [expr $element + 1]] [lindex $Router_Info [expr $element + 2]] [lindex $Router_Info [expr $element + 3]]"
}
incr element
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2015 08:18 PM
Arrays can return the elements out of order. List data structure referenced by index can return the data in the order required. Hostname can be captured without opening cli in the script.
set host [info hostname]
set Router_Info [list \
Router_A 1.1.1.0 1.1.12.1 1.1.11.2 \
Router_B 200.2.2.0 99.2.22.1 2.2.22.23 \
]
set element 0
foreach item $Router_Info {
if {[string equal $host $item]} {
puts "[lindex $Router_Info $element] [lindex $Router_Info [expr $element + 1]] [lindex $Router_Info [expr $element + 2]] [lindex $Router_Info [expr $element + 3]]"
}
incr element
}
