Cisco Support Community
Community Member

EEM CLI Script with parameters

Hi all,

I have a requirement to write an eem cli script that can be triggered using a pattern match and take parameters.

Basically the user has to do many repetitive tasks reconfiguring interfaces regularly. So instead of having to go into each interface individually and run the config that they can write a one word command and give it params which would be for example a comma separated list of interface names and then within my script i could parse the interface names and iterate over them performing the config operation on them.

so i'm just playing around with the cli policy.

::cisco::eem::event_register_cli occurs 1 pattern "nacdrop*" sync yes enter

# Import Namespaces
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*

array set arr_einfo [event_reqinfo]

set full_command $arr_einfo(msg)

puts $full_command

You can see here i want the command nacdrop to trigger this policy but when i try and run the command with arguments i get an error on the command line as its not a valid command and the policy doesnt trigger.

Ideal scenario run command

Router#nacdrop fastEthernet0/0,fastEthernet0/1,fastEthernet0/2

the script would then perform a set of config tasks on each of the 3 interfaces.

I thought the "enter" parameter to event_register_cli would do it as that is supposed to trigger the policy before the command is executed therefore before it determines it to be an invalid command. I do not have the latest version of eem however and suspect that the "enter" argument isn't being used as it isn't showing up as an option when i type ? to see what options are available although i don't get an error when registering the policy.

So my question is what version off eem was this "enter" argument introduced and will it allow me to run the policy and get around the invalid command problem.

Once i can run this policy and access the parameters to the cli command it opens up a lot for me in terms of automating repetitive tasks.

Hope someone can help.



Everyone's tags (1)

Accepted Solutions
Cisco Employee

Re: EEM CLI Script with parameters

Yes, the "enter" keyword allows you to react as soon as a matching command patter is typed on the prompt.  EEM will get the command before it is sent to the parser.  This will do what you seem to want to do.


Re: EEM CLI Script with parameters

Admittedly I'm not sure whether a tclsh or EEM Tcl script is more appropriate here, nor what "enter" is supposed to do in EEM, but the following should read in a comma-separated list of interfaces in good ol' Tcl:


foreach interfaceName [split [lindex $argv 0] ,] {
     puts "about to configure: $interfaceName..."

     # configure $interfaceName here


./test.exp fastEthernet0/0,fastEthernet0/1,fastEthernet0/2
expect version 5.42.0
argv[0] = /usr/bin/expect  argv[1] = -d  argv[2] = ./test.exp  argv[3] = fastEthernet0/0,fastEthernet0/1,fastEthernet0/2 
set argc 1
set argv0 "./test.exp"
set argv "fastEthernet0/0,fastEthernet0/1,fastEthernet0/2"
executing commands from command file ./test.exp
about to configure: fastEthernet0/0...
about to configure: fastEthernet0/1...
about to configure: fastEthernet0/2...

Cisco Employee

Re: EEM CLI Script with parameters

The "enter" keyword was added in EEM 3.0.  You also have a problem with your pattern.  You just want "nacdrop".  If you are still having problems, post the output of "show event manager version" and the output of "debug event manager detector cli" after reproducing the problem.

Community Member

Re: EEM CLI Script with parameters

Right gotya cheers Joe. It looks like I am running EEM 2.3 on my device here. So the enter command is not supported on my device. That doesn't matter as i will ultimately be deploying this script on devices with EEM 3.2. If you can confirm though that the enter parameter does what i think it should in that it should trigger the policy and not give me the "Invalid input..." and not the trigger the policy when i type something like "nacdrop fa0/0,fa0/1fa0/2" then i will be happy to write the script.

Cisco Employee

Re: EEM CLI Script with parameters

Yes, the "enter" keyword allows you to react as soon as a matching command patter is typed on the prompt.  EEM will get the command before it is sent to the parser.  This will do what you seem to want to do.

Community Member

Re: EEM CLI Script with parameters

Cheer Joe. That's great. I've attached the first draft of a script i've written, maybe someone else can find it useful too.

Basically it's for if you would like to perform the same operation on many interfaces you can use an alias and give it parameters


Router#vlanmove FastEthernet0/1-8,10,13-16

Notice the params use '-' and ',' When you use dash it will perform the operation on all the interfaces in a range and then comma is just for an individual interface and as you can see above you can mix ranges with individual ones.

The above example will give the output:

Configuring Interface: FastEthernet0/1

Configuring Interface: FastEthernet0/2

Configuring Interface: FastEthernet0/3

Configuring Interface: FastEthernet0/4

Configuring Interface: FastEthernet0/5

Configuring Interface: FastEthernet0/6

Configuring Interface: FastEthernet0/7

Configuring Interface: FastEthernet0/8

Configuring Interface: FastEthernet0/10

Configuring Interface: FastEthernet0/13

Configuring Interface: FastEthernet0/14

Configuring Interface: FastEthernet0/15

Configuring Interface: FastEthernet0/16

in the attached script just replace "puts "Configuring Interface: $interfaceName"

with your configuration


conf t

interface $interfaceName

switchport access vlan 2

and it will perform that operation on all intefaces in a range. I might update the script later to take config commands as env variables too. That would make the script more generic. But at the moment this script is useful for us as we have to regularly reconfigure interfaces.



Cisco Employee

Re: EEM CLI Script with parameters

Thanks for posting this, Joe.  I have one comment, and I would like to suggest you consider posting this to so that our larger EEM community can benefit from your work (when you complete the script).

Your pattern is not really what you want.  I think you should use, "^vlanmove" instead.  The way you have it written, it says, "match vlanmov followed by zero or more instances of 'e'".

CreatePlease to create content