Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. And see here for current known issues.

New Member

Problem with variable in scheduled job

I'm trying to get the following scheduled job to run:

switch(config)# scheduler job name backup_job
switch(config-job)# cli var name timestamp $(TIMESTAMP) ; copy running-config bootflash:/$(SWITCHNAME)-cfg.$(timestamp) ; copy bootflash:/$(SWITCHNAME)-cfg.$(timestamp) tftp://1.2.3.4/
switch(config-job)# exit
switch(config)# scheduler schedule name backup_timetable
switch(config-schedule)# job name backup_job
switch(config-schedule)# time daily 1:23
switch(config-schedule)# exit
switch(config)# exit

This job is taken directly from multiple Cisco MDS and Nexus documents. From what I can tell, the purpose of this job is to save the running configuration to a file on bootflash with date & time in the file name and then to copy the file from bootflash to tftp server.

I can create the job and schedule successfully:

switch(config)#show scheduler job name backup_job
Job Name: backup_job
--------------------
cli var name timestamp $(TIMESTAMP)
copy running-config bootflash:/$(SWITCHNAME)-cfg.$(timestamp)
copy bootflash:/$(SWITCHNAME)-cfg.$(timestamp) tftp://1.2.3.4

==============================================================================


switch(config)#show scheduler schedule name backup_timetable
Schedule Name       : backup_timetable
--------------------------------------
User Name           : admin
Schedule Type       : Run every day at 10 Hrs 48 Mins
Last Execution Time : Tue Mar  6 10:48:00 2012
Last Completion Time: Tue Mar  6 10:48:00 2012
Execution count     : 1
-----------------------------------------------
     Job Name            Last Execution Status
-----------------------------------------------
backup_job                        Success (0)
==============================================================================

The scheduled job runs successfully but the files that are created have the variable $(TIMESTAMP) in the file name instead of the actual date and time e.g. switch-cfg.$(TIMESTAMP)

The logfile contains the following:

Schedule Name  : backup_timetable                  User Name : admin
Completion time: Tue Mar  6 10:59:26 2012
--------------------------------- Job Output ---------------------------------
`cli var name timestamp $(TIMESTAMP)`
`copy running-config bootflash:/PEN-9509-2-cfg.$(TIMESTAMP) `
Copy complete, now saving to disk (please wait)...
`copy bootflash:/PEN-9509-2-cfg.$(TIMESTAMP) tftp://1.2.3.4 `
Trying to connect to tftp server......
Connection to server Established. Copying Started.....


It looks to me that the $(timestamp) variable is being created successfully and is being replaced with the $(TIMESTAMP) variable but this is not being replaced with the actual date and time.

The thing I don't get is that this looks to me that we're trying to nest variables and the same Cisco documents from which I get this configuration also state that nested variables are not allowed.

I have tried this on different hardware - MDS9500, MDS9100, Nexus 5000, Nexus 7000 and different software - SAN-OS 3.3, NX-OS 4.1, NX-OS 5.2 but cannot get it to work. I have also tried to put the commands in a script and run with the run-script command but it still does not work.

There is probably another method to achieve what this configuration is trying to achieve (and I would like to know if there is) but I want to know if this particular configuration will work.

Can anyone tell me if they have got this working or can see what I'm doing wrong or can try running this in a lab please?

3 REPLIES
Silver

Problem with variable in scheduled job

can you run this interactevly, works for me (4.2.7d)

copy startup-config tftp://192.168.1.45/9513$(TIMESTAMP)

@dynamoxxx
New Member

Problem with variable in scheduled job

Hi,

Thanks for answering.

"copy startup-config tftp://192.168.1.45/9513$(TIMESTAMP)" works fine.

This uses the system defined variable $(TIMESTAMP). The commands I am trying to run are using a user defined variable $(timestamp) which references the system defined variable $(TIMESTAMP) and it is this that doesn't seem to work for me.

New Member

Problem with variable in scheduled job

I managed to get this resolved with a bit of a workaround. If I put the copy commands in a script and pass the variable to the run-script command as part of the scheduled job then it works ok. Trying to create the variable within the script (or as a separate scheduled job command) still doesn’t work.

So, creating a script file (script) as follows:

copy running-config bootflash:/$(SWITCHNAME)-cfg.$(timestamp)
copy bootflash:/$(SWITCHNAME)-cfg.$(timestamp) tftp://1.2.3.4

and creating a scheduled job with the following command:

run-script bootflash:script timestamp=”$(TIMESTAMP)”

achieves the desired result.

836
Views
0
Helpful
3
Replies
CreatePlease login to create content