You can use environment variables and/or global variables to add the date to Autosys job standard out and error filenames.
NOTE: For Windows, you cannot use environment variables explicitly in the filenames. You must use global variables to reference the date.
CA Workload Automation AE
LINUX:
View the date change it to the desired format
[root@host123 /]# date
Fri Dec 22 08:13:10 CST 2017
Determine the desired date format
[root@host123 /]# date +'%m/%d/%Y'
12/22/2017
[root@host123 /]# date +'%Y/%m/%d' <-----------------(change format to YYYY/MM/DD)
2017/12/22
[root@host123 /]# date +'%Y-%m-%d' <-----------------(change the delimiters)
2017-12-22
NOTE: You CANNOT use a forward slash ‘/’ as a delimiter and you cannot escape the forward slash - the files will not get created.
A backslash ‘\’, a dash ‘-‘, an underscore ‘_’ and period ‘.’ have been tested as working delimiters.
=====================================================================================
Create a job that references the date in the std_out_file and std_err_file attributes:
/* ----------------- date_in_file ----------------- */
insert_job: date_in_file job_type: CMD
command: autoflags -a
machine: host123
owner: root@host123
permission:
date_conditions: 0
std_out_file: "/tmp/autologs/autoflags_log_$(date +'%m_%d_%Y').out"
std_err_file: "/tmp/autologs/autoflags_log_$(date +'%m_%d_%Y').err"
alarm_if_fail: 1
Start the job and verify the job ran to completion
[root@localhost bin]# sendevent -E STARTJOB -J date_in_file
[root@host123 bin]# autorep -J date_in_file -d
Job Name Last Start Last End ST/Ex Run/Ntry Pri/Xit
_____________________ ____________________ ____________________ _____ ________ _______
date_in_file 12/22/2017 08:59:23 12/22/2017 08:59:23 SU 58570/1 0
Status/[Event] Time Ntry ES ProcessTime Machine
-------------- --------------------- -- -- --------------------- ----------------------------------------
STARTING 12/22/2017 08:59:22 1 PD 12/22/2017 08:59:16 host123
RUNNING 12/22/2017 08:59:23 1 PD 12/22/2017 08:59:17 host123
<Executing at WA_AGENT>
SUCCESS 12/22/2017 08:59:23 1 PD 12/22/2017 08:59:17 host123
Check the directory where you specified your log files to be written to:
[root@host123 autologs]# pwd
/tmp/autologs
[root@host123 autologs]# ls -ltr
total 4
-rw-r--r--. 1 root root 0 Dec 22 08:10 autoflags_log_12_22_2017.err
-rw-r--r--. 1 root root 79 Dec 22 08:10 autoflags_log_12_22_2017.out
WINDOWS:
View the current date
C:\Users\Administrator>echo %DATE%
Fri 12/22/2017
Determine the desired date format
C:\Users\Administrator>echo %DATE:~4%
12/22/2017
C:\Users\Administrator>echo %DATE:~-10,2%-%DATE:~-7,2%-%DATE:~4%
12-22-2017
NOTE: You CANNOT use a forward slash ‘/’ or backslash ‘\’as a delimiter - the files will not get created.
A dash ‘-‘ and an underscore ‘_’ have been tested as working delimiters.
=====================================================================================
You can use Windows environment variables explicitly in the std_out_file and std_err_file attributes. You must use global variables to set the date and then reference the global variable in the job.
Create a job that references the date in a global variable (this particular job sets the date at the top of every hour):
/* ----------------- set_logdate ----------------- */
insert_job: set_logdate job_type: CMD
command: sendevent -E SET_GLOBAL -G logdate=“%DATE:~-10,2%_%DATE:~-7,2%_%DATE:~4%”
machine: test789
owner: Administrator@test789
permission:
date_conditions: 1
days_of_week: all
start_mins: 00
alarm_if_fail: 1
Verify that the global variable ‘logdate’ has been set by running the following command:
C:\Program Files\CA\Workload Automation AE>autorep -G logdate
Global Name Value
________________________________________________
logdate 2017_12_22
=====================================================================================
Create a job that references the ‘logdate’ global variable in the std_out_file and std_err_file attributes:
/* ----------------- date_in_file ----------------- */
insert_job: date_in_file job_type: CMD
command: autoflags -a
machine: test789
owner: Administrator@test789
permission:
date_conditions: 0
std_out_file: “C:\Temp\autoflags_log_$$(logdate).out”
std_err_file: “C:\Temp\autoflags_log_$$(logdate).err”
alarm_if_fail: 1
Start the ‘log’ job and verify the job ran to completion
C:\Program Files\CA\Workload Automation AE>sendevent -E STARTJOB -J date_in_file
C:\Program Files\CA\Workload Automation AE>autorep -J date_in_file -d
Job Name Last Start Last End ST/Ex Run/Ntry Pri/Xit
_____________________ ____________________ ____________________ _____ ________ _______
date_in_file 12/22/2017 09:33:59 12/22/2017 09:34:00 SU 3/1 0
Status/[Event] Time Ntry ES ProcessTime Machine
-------------- --------------------- -- -- --------------------- ----------------------------------------
STARTING 12/22/2017 09:33:54 1 PD 12/22/2017 09:33:57 test789
RUNNING 12/22/2017 09:33:59 1 PD 12/22/2017 09:34:00 test789
<Executing at WA_AGENT>
SUCCESS 12/22/2017 09:34:00 1 PD 12/22/2017 09:34:01 test789
Check the directory where you specified your log files to be written to