First EEM script: make a backup of the config

Answered Question
Apr 24th, 2009

Hi all,

I am trying to write my first EEM script. The goal is that whenever someone change the config, a backup is written on flash.

I have the following:

file prompt quiet

event manager applet ConfigSync

event syslog occurs 1 pattern "\%SYS-5-CONFIG_I: Configured" maxrun 90

action 1.0 cli command "enable"

action 2.0 cli command "copy running bootflash:/latest-cfg"

but it doesn't seem to work. Any ideas ?

(the script is triggered, when i add a syslog action, i see the log, so that works)

I have this problem too.
0 votes
Correct Answer by Joe Clarke about 7 years 7 months ago

No, you won't create a loop since only one instance of the policy can run at one time.

I'm betting your problem is with command authorization. If you are using AAA command authorization, you may have to add:

event manager session cli username USER

Where USER is a username which is authorized to run the specified CLI commands.

  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 4.8 (3 ratings)
Loading.
yjdabear Fri, 04/24/2009 - 08:16

Seems to me "file prompt quiet" needs to be configured from within the eem applet itself:

event manager applet ConfigSync

event syslog occurs 1 pattern "\%SYS-5-CONFIG_I: Configured" maxrun 90

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 "copy running bootflash:/latest-cfg"

action 3.0 cli command "config t"

action 3.1 cli command "no file prompt quiet"

action 3.2 cli command "end"

Joe Clarke Fri, 04/24/2009 - 08:52

This is not necessary. As long as file prompt quiet is configured, the applet should work. Of course, unless you want file prompt quiet to be in effect constantly, doing it within the applet is preferred.

Seeing the output of "debug event manager action cli" would be helpful assuming file prompt quiet is actually configured.

That said, while EEM works for this task, you might want to check out the built-in config archive feature of IOS which offers a bit more features. See http://www.cisco.com/en/US/docs/ios/12_3t/12_3t7/feature/guide/gtrollbk.html#wp1100253 for more details.

gnijs Fri, 04/24/2009 - 10:55

1) i am familiar with the config archive feature. However, you can only specify one location. I want a copy on the local bootflash and also a copy in the flashcard inserted in the supervisor

2) i will try to get you the debug output

3) i did not want to implement the "file prompt quiet" inside the script, because look at the trigger: the script is triggered when you exit config mode. If i exit config mode within the script ("end action"), don't i create a recursive loop ??

mvg,

Geert

Correct Answer
Joe Clarke Fri, 04/24/2009 - 11:05

No, you won't create a loop since only one instance of the policy can run at one time.

I'm betting your problem is with command authorization. If you are using AAA command authorization, you may have to add:

event manager session cli username USER

Where USER is a username which is authorized to run the specified CLI commands.

yjdabear Fri, 04/24/2009 - 11:23

Is the single-threadedness of EEM execution subject to change, or is it in place because of looping concerns like this?

Joe Clarke Fri, 04/24/2009 - 11:35

You can configure it so multiple policies can run at the same time now. For example, to configure the default queue to allow two policies to run simultaneously:

event manager scheduler script thread class default number 2

The default is 1.

gnijs Fri, 04/24/2009 - 12:47

Thanks jclarke, that was it: AAA.

Adding the above command worked.

yjdabear Fri, 04/24/2009 - 11:10

Yeah, you're right. It could be kludgily dealt with by turning on/off or adjusting the syslogging level along with "file prompt quiet", but that's not worth the trouble given it's unnecessary.

Here's an alternative approach using EEM tcl policy that seems easily adatable to do what you want near the end of this page:

http://www.cisco.com/en/US/products/ps6815/products_white_paper0900aecd803a4dad.shtml

Actions

This Discussion