08-30-2021 07:00 AM - edited 08-30-2021 07:04 AM
Hello,
I try to find the right syntax to have timestamp on my backup file name - via ftp (EEM Scripting) - on Catalyst 9K platform
So if I use archive I can do :
archive
path ftp://10.0.0.10//$h/$h_$t.cfg
But if I try to directly put the command "copy run ftp://10.0.0.10//$h/$h_$t.cfg " it doesn't work
First because directory name is not recognised. And if I try with right directory name I finally have a file with name "$h_$t.cfg"
The goal is to use this command on EEM Scripting
kron policy-list Backup-FTP
cli event manager run Backup-FTP
kron occurrence Backup-FTP at 5:00 recurring
policy-list Backup-FTP
event manager applet Backup-FTP
event none
action 10.0 cli command "enable"
action 20.0 cli command "copy run ftp://10.0.0.10//$h/$h_$t.cfg "
As a work around I set archive with path then I just ask a "write mem" on my script but I don't want to have a backup on each "write mem"
Thanks in advance
Rémi
Solved! Go to Solution.
08-30-2021 12:40 PM
Hello,
for the timestamp, you could use the $_event_pub_sec variable, but this would give you an epoch (basically a random number) timestamp.
The script below would give you the exact Year/Month/Day/Hour/Minute/Second:
event manager applet test
event none
action 0.01 info type routername
action 1.01 cli command "enable"
action 1.02 cli command "show clock"
action 1.03 regexp "(2[0-3]|[01][0-9]):([0-6][0-9]):([0-6][0-9])" "$_cli_result" time hour minute second
action 1.04 puts "$time"
action 1.05 puts "$hour"
action 1.06 puts "$minute"
action 1.07 puts "$second"
action 1.11 cli command "show clock"
action 1.12 regexp "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ([1-9]|0[1-9]|[1-2][0-9]|3[0-1]) (20[1-9][0-9])" "$_cli_result" time2 month day year
action 1.13 puts "$time2"
action 1.14 puts "$month"
action 1.15 puts "$day"
action 1.16 puts "$year"
action 2.01 cli command "configure terminal"
action 2.02 cli command "file prompt quiet"
action 2.03 cli command "do copy run ftp://10.0.0.10/$_info_routername-$year$month$day-$hour$minute$second.txt"
08-30-2021 12:40 PM
Hello,
for the timestamp, you could use the $_event_pub_sec variable, but this would give you an epoch (basically a random number) timestamp.
The script below would give you the exact Year/Month/Day/Hour/Minute/Second:
event manager applet test
event none
action 0.01 info type routername
action 1.01 cli command "enable"
action 1.02 cli command "show clock"
action 1.03 regexp "(2[0-3]|[01][0-9]):([0-6][0-9]):([0-6][0-9])" "$_cli_result" time hour minute second
action 1.04 puts "$time"
action 1.05 puts "$hour"
action 1.06 puts "$minute"
action 1.07 puts "$second"
action 1.11 cli command "show clock"
action 1.12 regexp "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ([1-9]|0[1-9]|[1-2][0-9]|3[0-1]) (20[1-9][0-9])" "$_cli_result" time2 month day year
action 1.13 puts "$time2"
action 1.14 puts "$month"
action 1.15 puts "$day"
action 1.16 puts "$year"
action 2.01 cli command "configure terminal"
action 2.02 cli command "file prompt quiet"
action 2.03 cli command "do copy run ftp://10.0.0.10/$_info_routername-$year$month$day-$hour$minute$second.txt"
09-06-2021 07:24 AM - edited 09-06-2021 07:32 AM
Big thank you for this amazing script Georg Pauwen
I adapted action 2.03 to place backup file in a different directory for each hostname
action 2.03 cli command "do copy run ftp://10.0.0.10/$_info_routername/$_info_routername-$year$month$day-$hour$minute$second.txt"
Once again thanks for your time Georg.
05-06-2022 09:46 AM
Georg (or anyone else),
I like what you've provided to help us, Thanks.
Is there a away to not have log entries for the put actions? I get a lot of this, and just the act of extracting to a variable, I don't need a log for. Other EM logging I would think good to retain, I just don't need these creation of a variable logs.
Mar 30 00:52:07.494: %HA_EM-6-LOG: test3: 00:52:07
Mar 30 00:52:07.494: %HA_EM-6-LOG: test3: 00
Mar 30 00:52:07.494: %HA_EM-6-LOG: test3: 52
Mar 30 00:52:07.494: %HA_EM-6-LOG: test3: 07
Mar 30 00:52:07.508: %HA_EM-6-LOG: test3: Mar 30 2011
Mar 30 00:52:07.508: %HA_EM-6-LOG: test3: Mar
Mar 30 00:52:07.508: %HA_EM-6-LOG: test3: 30
Mar 30 00:52:07.508: %HA_EM-6-LOG: test3: 2011
Thanks.
05-06-2022 10:19 AM
Hello,
I think you can get rid of all the 'puts', they are not really necessary for the script to run. The below should be sufficient:
event manager applet test
event none
action 0.01 info type routername
action 1.01 cli command "enable"
action 1.02 cli command "show clock"
action 1.03 regexp "(2[0-3]|[01][0-9]):([0-6][0-9]):([0-6][0-9])" "$_cli_result" time hour minute second
action 1.11 cli command "show clock"
action 1.12 regexp "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ([1-9]|0[1-9]|[1-2][0-9]|3[0-1]) (20[1-9][0-9])" "$_cli_result" time2 month day year
action 2.01 cli command "configure terminal"
action 2.02 cli command "file prompt quiet"
action 2.03 cli command "do copy run ftp://10.0.0.10/$_info_routername-$year$month$day-$hour$minute$second.txt"
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide