cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
8672
Views
5
Helpful
8
Replies

EEM Backup Script to Include Timestamp?

devils_advocate
Level 7
Level 7

Hi

So we use a range of switches and they don't all support auto archive and/or Kron etc. Therefore we have settled on EEM to automate their config backups when something changes.

Below is my script:

event manager applet Backup-Running-Config-To-TFTP
description Backup-Running-Config-To-TFTP
event syslog pattern "%SYS-5-CONFIG_I: Configured from"
action 0.1 info type routername
action 1.0 cli command "enable"
action 1.1 cli command "copy run tftp" pattern "Address"
action 1.2 cli command "192.168.5.4" pattern "filename"
action 1.3 cli command "$_info_routername-confg"
action 2.0 syslog priority informational msg "Configuration change detected. Write to TFTP succesfully executed"!

However, this is going to create the same filename for each new backup with a (1), or (2) at the end for new ones.

What I want is to add a timestamp at the end of each filename and I have found the below variable but I am unsure where to put it in the script?

_$_event_pub_time

Thanks!

2 Accepted Solutions

Accepted Solutions

Joe Clarke
Cisco Employee
Cisco Employee

Really it would be best to use $_event_pub_sec as this will give you an epoch timestamp without any spaces or special characters.  It has second accuracy, so it should be perfect for this use case.

View solution in original post

You have a typo.  Try:

action 1.3 cli command "$_info_routername-config_$_event_pub_sec"

View solution in original post

8 Replies 8

Joe Clarke
Cisco Employee
Cisco Employee

Really it would be best to use $_event_pub_sec as this will give you an epoch timestamp without any spaces or special characters.  It has second accuracy, so it should be perfect for this use case.

Hi Joe

where abouts would this go in the script?

as a separate line or part of action 1.3?

thanks

action 1.3 cli command "$_info-routername-config_$_event_pub_sec"

Hmmm ok, so I am getting this error:

Jan 9 21:18:33.508: %HA_EM-3-FMPD_UNKNOWN_ENV: fh_parse_var: could not find environment variable: _info
Jan 9 21:18:33.508: %HA_EM-3-FMPD_ERROR: Error executing applet Backup-Running-Config-To-TFTP statement 1.3

Script is - 

event manager applet Backup-Running-Config-To-TFTP
description Backup-Running-Config-To-TFTP
event syslog pattern "%SYS-5-CONFIG_I: Configured from"
action 0.1 info type routername
action 1.0 cli command "enable"
action 1.1 cli command "copy run tftp" pattern "Address"
action 1.2 cli command "192.168.4.5" pattern "filename"
action 1.3 cli command "$_info-routername-config_$_event_pub_sec"
action 2.0 syslog priority informational msg "Configuration change detected. Write to TFTP succesfully executed"!

Ok so I think my switch (3750x) supports EEM but not the Environment variables which is annoying.

I have changed the script to just read:

action 1.3 cli command "hostname-config"

This seems to work fine but it doesn't create a new file for each config write, it just appends the existing file.

Is there any way round this?

Thanks

You have a typo.  Try:

action 1.3 cli command "$_info_routername-config_$_event_pub_sec"

Yep, that did the trick.

Thanks!

It looks like the timestamp is in epoch format. Is it possible to format "$_event_pub_sec" into other format like yyyymmdd?


 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: