How can I include a date/time stamp in my stdout/stderr filename for Autosys in Windows?
This can be done using global variables in your job. The variable must be set prior to running the job, it is not dynamic.
Here is an example:
1) First create a global variable with the following parameters (2 examples):
a. sendevent -E SET_GLOBAL -G mydate=%DATE:~4,2%.%DATE:~7,2%.%DATE:~10,4%
b. sendevent -E SET_GLOBAL -G mydate=%DATE:~12,2%%DATE:~4,2%%DATE:~7,2%_%TIME:~0,2%%TIME:~3,2%
2) Next create a job using the global variable:
Example a:
insert_job: envj job_type: CMD
command: dir
machine: autosysj
owner: Administrator@autosysj
permission:
date_conditions: 0
std_out_file: c\:\test.$$mydate.txt
std_err_file: c\:\test.$$mydate.txt
alarm_if_fail: 1
----
Example b: (Includes the job name in the filename)
std_out_file: "C:\Users\%AUTO_JOB_NAME%.$$mydate.out"
std_err_file: "C:\Users\%AUTO_JOB_NAME%.err"
Resulting filename:
Test-Date.180510_1027.out
The next time the job is started, the std-out/std-err will include the date or date-time value depending on how the variable was set.
C:\>sendevent -E STARTJOB -j envj
C:\>dir test*.*
Volume in drive C has no label.
Volume Serial Number is 18FB-3B31
Directory of C:\
05/7/2018 09:22 AM 2,776 test.05.07.2018.txt
Additional Date strings that could be used in a global variable setting:
===========================================================
set JOB_W_DATE_YYYYDDMM=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
C:\Program Files (x86)\CA\Workload Automation AE>echo %JOB_W_DATE_YYYYDDMM
20180509
set JOB_W_DATE_YYYYMMDD=%DATE:~10,4%%DATE:~7,2%%DATE:~4,2%
C:\Program Files (x86)\CA\Workload Automation AE>echo %JOB_W_DATE_YYYYMMDD%
20180905
set JOB_W_DATE_YYDDMM=%date:~-2%%date:~4,2%%DATE:~7,2%
C:\Program Files (x86)\CA\Workload Automation AE>echo %JOB_W_DATE_YYDDMM%
180509
set JOB_W_DATE_YYMMDD=%date:~-2%%DATE:~7,2%%date:~4,2%
C:\Program Files (x86)\CA\Workload Automation AE>echo %JOB_W_DATE_YYMMDD%
180905
set JOB_DATE=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
C:\Program Files (x86)\CA\Workload Automation AE>echo %JOB_DATE%
20180510