Save config to TFTP with EEM

Answered Question
Jan 12th, 2009

Hi.

I'm trying out the EEM for the first time. I have written an applet that looks like this:

event manager applet SaveConfigToTFTP

event cli pattern "write" sync no skip no

action 1 cli command "enable"

action 2 cli command "configure terminal"

action 3 cli command "file prompt quiet"

action 4 cli command "end"

action 5 cli command "copy running-config tftp://tftp-server/router-confg"

action 6 cli command "configure terminal"

action 7 cli command "no file prompt quiet"

action 8 cli command "end"

It seems to work the first time I use it but not after that(the trigger is write). When I debug I can see that the script is running everytime i use write but when I check on the TFTP-server the file is not there. If i do a wr n manually i can see the file on the TFTP-server. Any idea what I'm doing wrong? Thanks.

/Daniel

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

The commands are always expanded before being passed to EEM. So, "write memory" will work just fine. To also match "copy running-config startup-config", you could try:

"(write memory|copy running-config startup-config)"

To set a timer, your applet could configure another, timer applet to run. For example:

action 010 cli command "event manager applet mytimer"

action 011 cli command "event timer countdown time 30"

action 012 cli command "action ..."

  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 5 (3 ratings)
Loading.
Joe Clarke Mon, 01/12/2009 - 08:31

What is the output of "debug event manager action cli" when running this policy?

daniel.dib Mon, 01/12/2009 - 23:19

Hi. This is the output. I have removed the real hostname and banner for privacy. I have added the output as an attachment because of the 4000 character limit.

Looks OK to me, however there is no file on TFTP with that timestamp.

/Daniel

Attachment: 
Joe Clarke Mon, 01/12/2009 - 23:31

The debug shows the transfer occurring. And the "!!" shows that the file was transferred successfully. Perhaps the TFTP server is not syncing the file to disk, or is renaming it internally. If this were a standard UNIX tftpd, a file router-confg would have to exist on the server with global write permissions. After the transfer, the files modify time would have been updated.

If you wanted to double-check IOS, you could get a sniffer trace of TFTP traffic (basically all UDP) between the device and the TFTP server at the time of the transfer. But based on this debug, and the applet itself, I think IOS is behaving correctly.

daniel.dib Tue, 01/13/2009 - 05:31

My applet seems to work indeed. Now another question. I tried to match several strings with event cli pattern. I want to match all commands that save to NVRAM and exclude wr n and copy run tftp. I want to match "wr", "write", "wr mem", "write mem", "write memory", "copy run start", "copy running-config startup-config" but not match "wr n" and "copy run tftp". Can i do this with regex? Is it possible to match a pattern and also set a timer?

/Daniel

Correct Answer
Joe Clarke Tue, 01/13/2009 - 09:49

The commands are always expanded before being passed to EEM. So, "write memory" will work just fine. To also match "copy running-config startup-config", you could try:

"(write memory|copy running-config startup-config)"

To set a timer, your applet could configure another, timer applet to run. For example:

action 010 cli command "event manager applet mytimer"

action 011 cli command "event timer countdown time 30"

action 012 cli command "action ..."

daniel.dib Tue, 01/13/2009 - 11:36

Nice, thank you. I eventually found a regex that worked. I used "(^write$|write memory|copy running-config startup-config)". Once again I greatly appreciate your help.

mfawehin Thu, 04/30/2009 - 00:36

Hi Daniel,

I am trying to do the same thing but have not configured EEM before, I've used Kron scripts but the device I'm want to copy the config from does not have a supported IOS version for kron - 12.2

Please paste the EEM portion of your config so I know how to configure the switch to send its running config to a tftp server at a scheduled time (4am) once a week.

Many thanks,

Martha.

Actions

This Discussion