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

Way to specify a "return code" on the CLI?

Is there a way to send a "return code" on the CLI in IOS? Being able to send a return code would allow multiple commands to be sent on the same command line. For instance:

conf t; int e0/1; no shut; exit; exit; copy run start

Something like that. Anyone know if this is possible?

Thanks,

- aa

1 REPLY
Cisco Employee

Re: Way to specify a "return code" on the CLI?

You can use the Embedded Event Manager to accomplish this. For example:

event manager applet no_shut_e_0_1

event none

action 1.0 cli command "enable"

action 2.0 cli command "config t"

action 3.0 cli command "int e0/1"

action 4.0 cli command "no shut"

action 5.0 cli command "end"

action 6.0 cli command "write mem"

!

alias exec noshute_0_1 event manager run no_shut_e_0_1

Then, from exec mode, just run:

Router#noshute_0_1

And interface e0/1 will be set administratively up. Note: the "alias exec" is not required, but it makes creating custom IOS commands easier. Without it, you would have to run "event manager run no_shut_e_0_1" each time you wanted to execute the applet.

However, this does not make use of returns codes as you asked about initially. Using return codes together with EEM is also possible. This gives you a way to intercept certain commands, and choose not to run them. For example, to intercept the command "show ip ospf neighbors" and not run it, do:

event manager applet no_ip_ospf_nei

event cli pattern "show ip ospf neighbor" sync yes

action 1.0 syslog msg "DANGER: CLI command $_cli_msg was attempted (but not executed)" priority critical

set 2.0 _exit_status 0

Now when "show ip ospf neighbor" is typed, EEM will intercept it, send out a critical syslog message, and ignore the command.

More about the Embedded Event Manager can be found at http://www.cisco.com/en/US/products/ps6441/products_configuration_guide_book09186a008054dddf.html

404
Views
5
Helpful
1
Replies
CreatePlease login to create content