cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2169
Views
0
Helpful
2
Replies

Conditional Logic Based on Command Output

johnstack8
Level 1
Level 1

In an EEM applet I want to use the output of a show command to decide if I need to make a change.

Here's the command whose output that I want to use:

BGP-DC2#sh run | i ^ neighbor 9.9.9.9 prefix-list

neighbor 9.9.9.9 prefix-list announce out

The prefix-list will either be announce or no-announce, if the prefix list is no-announce then I need to run a command to change it.

I feel that there must be an incredibly easy answer to this question but I can't find anything. I suspect that I somehow need to use the regex command or the action command pattern option.

Thanks in advance for your help.

2 Replies 2

johnstack8
Level 1
Level 1

I found this page [1] and it lead me to the following solution:

action 02.0 cli command "show run | i ^ neighbor 9.9.9.9 prefix-list"
action 02.5 set active_prefix_list "none"
action 03.0 regexp "prefix-list ([^ ]+)" $_cli_result result active_prefix_list
action 04.0 if $active_prefix_list eq no-announce
action 05.0   syslog msg "no-announce prefix-list in place, restoring announce prefix list"
action 06.0   cli command "conf t"
[...]

action 10.0 else
action 11.0   syslog msg "announce prefix-list in place, making no changes"
action 12.0 end

[1] http://wiki.nil.com/Regular_expressions_in_Embedded_Event_Manager_applets

Yep, that should work.  Though you may need to check your spacing.  Hard to know here as HTML may be messing with stuff.