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.

13 comments:

  1. How can you pass a parameter?
  2. You cannot pass a parameter when using EEM applet, you need Tcl script to do that. I'll cover that in a future post.
  3. Please show the example with the interactive tcl script - how to pass the parameter to the command
  4. 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 ?
  5. I was able to figure out the reload specific solution. No luck about other prompty commands yet.
  6. 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
  7. Thanks for the post!
    I configured the following applet:
    event manager applet DebugSIP
    event none
    action 1.0 cli command "debug ccsip messages"
    action 2.0 cli command "terminal monitor"
    !
    I run it with:# event manager run DebugSIP
    Yet I don't get any messages on the terminal..
    Any idea why?
    Thanks again,
    Gabriel
    Replies
    1. The "cli command" lines are executed in a context of a different VTY line (EEM script opens a "console" session to execute them), so the "terminal monitor" command doesn't apply to your current session. I wrote a blog post about this, just search some more ;)

      A tcl script executed with tcl command might do the trick (don't remember the details, it's been a long time). Yet again, I probably published at least one example of how that's done.
    2. Thanks for your reply! I tried the following TCL script:
      puts [open "flash:debugSIPon" w+] {
      exec "debug ccsip messages"
      exec "terminal monitor"
      }
      when I execute it
      tclsh flash:debugSIPon
      I don't get any error, but no output to vty either.
      Thanks
    3. Don't use "exec", just include CLI commands in TCL script. See

      http://wiki.nil.com/Executing_IOS_commands_from_Tcl_shell
  8. I was finally able to combine tcl + alias to turn sip debug with just typing dsip, and turn it off with usip, thanks to http://blog.ipspace.net/2008/01/copy-text-files-into-router-flash.html and this one.
    Thanks for your quick response!!
Add comment
Sidebar