cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3347
Views
0
Helpful
7
Replies

EEM action command, rewrite a file without asking for confirmation

asarlo
Level 1
Level 1

Hello, I'am checking the CPU threshold with EEM in a 6509 switch (12.2.18SXF9) with SUP-720-3B. When the CPU is over a preconfigured value, I want to copy the "show process cpu sorted" command to a file cpu.txt in the sup-bootflash, and if the file already exist,I want to rewrite it without asking me for confirmation. Can I do that ?

The following sample did not work, because always ask me for confirmation.

event manager applet Chequeo_CPU

event snmp oid 1.3.6.1.4.1.9.9.109.1.1.1.1.3.1 get-type exact entry-op ge entry-val 5 poll-interval 10

action 1.0 cli command "enable"

action 2.0 cli command "term exec prompt time"

action 3.0 cli command "show process cpu sorted | tee sup-bootflash:/cpu.txt"

action 4.0 snmp-trap strdata "Utilizacion CPU supero 5%, valor actual=$_snmp_oid_val%"

action 5.0 syslog msg "Utilizacion CPU supero 5%, valor actual=$_snmp_oid_val%"

!

end

Thanks a lot in advance.

Regards, Anacelia

7 Replies 7

Joe Clarke
Cisco Employee
Cisco Employee

Probably the easiest way to do this is by configuring "file prompt quiet". You can do this globably, or do this in your EEM policy:

action 2.1 cli command "config t"

action 2.2 cli command "file prompt quiet"

action 2.3 cli command "end"

action 3.1 cli command "config t"

action 3.2 cli command "no file prompt quiet"

action 3.3 cli command "end"

Thanks to answer me. I have another question, is there a difference between enabling "file prompt quiet" command from EEM policy than globally ?. My question is, because If I enable this command from the EEM policy, just at this time, somebody from another terminal session,execute "delete file" command before executing "no file prompt quiet" in this situation it sould not ask for confirmation. Isn't it.

Thanks!

Anacelia

There is no difference between enabling it globally and enabling it from the policy. It's just the the command has a limited lifespan when configured from the policy. Delete commands will still prompt when "file prompt quiet" is enabled.

OK ! thanks a lot for your help.

Regards, Anacelia

Hello, I tried the way you suggest but didn't run.

I tried putting (file prompts quiet command globally and from the applet) this config :

event manager applet Chequeo_CPU

event snmp oid 1.3.6.1.4.1.9.9.109.1.1.1.1.3.1 get-type exact entry-op ge entry-val 1 poll-interval 10

action 1.0 cli command "enable"

action 1.1 cli command "config t"

action 1.2 cli command "file prompt quiet"

action 1.3 cli command "end"

action 2.0 cli command "enable"

action 2.1 cli command "show process cpu sorted | tee disk0:cpu.txt"

action 2.2 snmp-trap strdata "Utilizacion CPU supero 1%, valor actual=$_snmp_oi

"

action 2.3 syslog msg "Utilizacion CPU supero 1%, valor actual=$_snmp_oid_val%

action 3.0 cli command "config t"

action 3.1 cli command "no file prompt quiet"

action 3.3 cli command "end"

Do you have any other suggestion ?

I enabled the "debug event manager action cli" command and I'am attaching also the debug log.

Thanks a lot!

Regards, Anacelia

I forgot, tee doesn't obey file prompt quiet in this release. Your choices are to either convert this policy to a Tcl policy which will allow you to write out the file using Tcl, or use a different operation. For example, tee the contents to a temporary file, then copy this file to the final file:

action 2.1 cli command "show process cpu sorted | tee disk0:cpu_tmp.txt

action 2.2 cli command "copy disk0:cpu_tmp.txt disk0:cpu.txt"

action 2.3 cli command "delete /force disk0:cpu_tmp.txt"

I found this thread while trying to do something similar.

 

I always try to avoid any sort of config whenever possible. That way it won't mark the config as dirty. Also, making change in the config opens you to potential race conditions, say another script may be running and expecting the file prompt or your script may end unexpectedly. The config could be saved in between, etc.

 

Instead, I suggest using the "rename" and "delete" combinations.

 

action 2.1 cli command "delete /force cpu_tmp.txt"

action 2.2 cli command "rename cpu.txt cpu_tmp.txt" pattern "cpu_tmp.txt"

action 2.3 cli command ""

 

 

if the file is not present, rename will not trigger a prompt.