ALERT: Some images may not load properly within the Knowledge Base Article. If you see a broken image, please right-click and select 'Open image in a new tab'. We apologize for this inconvenience.

Adding a date time stamp to a standard out file name in Windows


Article ID: 32782


Updated On:


CA Workload Automation AE - Business Agents (AutoSys) CA Workload Automation AE - Scheduler (AutoSys) Workload Automation Agent


A How-to guide on adding a date/timestamp to your std_out and std_err files for Autosys in a Windows environment


Release: ATSYHA99000-11.3.6-Workload Automation AE-High Availability Option




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: [email protected]


     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:

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

  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%

  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%

  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%

  set JOB_DATE=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2% 
    C:\Program Files (x86)\CA\Workload Automation AE>echo %JOB_DATE%