Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. And see here for current known issues.

New Member

Conditional Logic Based on Command Output

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.

Everyone's tags (3)
2 REPLIES
New Member

Conditional Logic Based on Command Output

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

Cisco Employee

Conditional Logic Based on Command Output

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

761
Views
0
Helpful
2
Replies
CreatePlease login to create content