11-25-2014 07:40 AM
Hello Guys,
I’m trying to create a script which is controlled by an EEM-UPDOWN event of an interface. What I’m trying to do is, if interface X is down for some reason it should copy the interface configuration to interface Y.
So my problem is I’m very new to eem-tcl scripting and I have some basic problem hopefully u can help me =) I’m working on a ASR9K !
So what i have done so fare:
::cisco::eem::event_register_syslog occurs 1 pattern ".*CHANGED.*$_sat_1_link_1.*" maxrun 90
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
array set arr_einfo [event_reqinfo]
if {$_cerrno != 0} {
set result [format "component=%s; subsys err=%s; posix err=%s;\n%s" \
$_cerr_sub_num $_cerr_sub_err $_cerr_posix_err $_cerr_str]
error $result
}
if [catch {cli_open} result] {
error $result $errorInfo
} else {
array set cli1 $result
}
action_syslog priority emergencies msg "start script testv1_1"
#puts "\nEXECUTE CLI COMAND :\n"
set out {cli_exec $cli1(fd) "show running-config formal interface $_sat_1_link_1"}
set xout [split $out \n]
#puts "DEBUG : $xout \n\n"
set anz [llength $xout]
#puts "DEBUG : count rows = $anz \n\n"
for {set ii "0"} {$ii < $anz } {incr ii} {
set indexout [lindex $out $ii]
regexp {([\w]+)[ ]([\w\d/]+)\s(.*)} $indexout a b c d
#puts "\nDEBUG START"
#puts "\nindex Nr $ii"
#puts "Full Match: $a"
#puts "Sub Match1: $b"
#puts "Sub Match2: $c"
#puts "Sub Match3: $d"
#puts "DEBUG END\n"
set intsrc {cli_exec $cli1(fd) "no $b $_sat_1_link_1 $d"}
set intdest {cli_exec $cli1(fd) "$b $_sat_1_link_2 $d"}
}
if [catch {cli_exec $cli1(fd) "commit"} result] {
error $result $errorInfo
}
if [catch {cli_exec $cli1(fd) "end"} result] {
error $result $errorInfo
}
action_syslog priority emergencies msg "End script testv1_1"
ps. $_sat_1_link_1 and $_sat_1_link_2 are globaly set per cli in the event manager env.
Thanks for your help and hopefully u can help me with this script
Solved! Go to Solution.
11-27-2014 11:37 AM
What about this:
set output [cli_exec $cli(fd) "show run interface $ointf"]
cli_exec $cli(fd) "config t"
cli_exec $cli(fd) "default int $intf"
cli_exec $cli(fd) "int $intf"
foreach line [split $output "\n"] {
if { [regexp {^ } $line] } {
cli_exec $cli(fd) $line
}
}
cli_exec $cli(fd) "commit"
cli_exec $cli(fd) "end"
11-25-2014 09:47 AM
What problem are you having and what is the output of the various CLI commands?
11-27-2014 03:42 AM
Hey
after show running-config formal interface TenGigE 0/0/2/1 the cli output example is :
interface TenGigE0/0/2/1 description Test: 0-43
interface TenGigE0/0/2/1
interface TenGigE0/0/2/1 shutdown
and now i want to split the config with my regex
regexp {([\w]+)[ ]([\w\d/]+)\s(.*)} $indexout a b c d
As example line 1
set x= "TenGigE0/0/2/2" --> =dest_interface
a= interface TenGigE0/0/2/1 description Test: 0-43
b= interface
c= TenGigE0/0/2/1
d= description Test: 0-43
do this
cli_exec $cli1(fd) "no $b $c $d" --->no interface TenGig E0/0/2/1 description Test: 0-43
cli_exec $cli1(fd) " $b $x $d" ---> interface TenGigE0/0/2/2 description Test: 0-43
and from this point it shoud do this until there are no config lines =)
as a final result is should copy the whole config from interface X to interface Y if the trigger is active
but as i see, the main problem is to get the CLI output in a format like this
set xy = interface TenGigE0/0/2/1 description Test: 0-43\ninterface TenGigE0/0/2/1\ninterface TenGigE0/0/2/1 shutdown
or in an index like this:
Index | command
1 interface TenGigE0/0/2/1 description Test: 0-43
2 interface TenGigE0/0/2/1
3 interface TenGigE0/0/2/1 shutdown
Thx
11-27-2014 11:37 AM
What about this:
set output [cli_exec $cli(fd) "show run interface $ointf"]
cli_exec $cli(fd) "config t"
cli_exec $cli(fd) "default int $intf"
cli_exec $cli(fd) "int $intf"
foreach line [split $output "\n"] {
if { [regexp {^ } $line] } {
cli_exec $cli(fd) $line
}
}
cli_exec $cli(fd) "commit"
cli_exec $cli(fd) "end"
11-28-2014 01:06 AM
Thank for your much simpler solution of the script !
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide