Execute multiple commands at once

Sometimes you'd like to automate execution of command sequences or create a command alias that would trigger a series of commands. One way of achieving this is by creating an EEM applet. For example, to clear IP routing table and reset BGP neighbors, define the following EEM applet:

event manager applet ClearAll
event none
action 1.0 cli command "clear ip route *"
action 2.0 cli command "clear ip bgp *"
You can trigger this applet with the event manager run ClearAll command or you could configure a command alias, for example alias exec cleanup event manager run ClearAll.

Note: this article is part of You've asked for it series.

8 comments:

Anonymous said...

How can you pass a parameter?

Ivan Pepelnjak said...

You cannot pass a parameter when using EEM applet, you need Tcl script to do that. I'll cover that in a future post.

Michal said...

Please show the example with the interactive tcl script - how to pass the parameter to the command

Ivan Pepelnjak said...

The complete example is posted here.

Michal said...

ok but can you make a script with deals with such situation - sometimes when you put command you have to confirm it

like e.g reload
[confirm] ENTER
how to confirm command in the tcl script ?

Ivan Pepelnjak said...

I was able to figure out the reload specific solution. No luck about other prompty commands yet.

Michal said...

Yes reload is specific but other clear or delete commands which require confirmation are different maybe a interior variable some kind of event handler? I am still looking for this

Ivan Pepelnjak said...

The typeahead command worked for me in IOS release 12.4(15)T.

Ivan Pepelnjak, CCIE#1354, is the chief technology advisor for NIL Data Communications. He has been designing and implementing large-scale data communications networks as well as teaching and writing books about advanced technologies since 1990. See his full profile, contact him or follow @ioshints on Twitter.