AutoSys Workload Automation

  • 1.  what exit code should I use on my batch script to make the job go to terminated status instead of failure

    Posted Jan 02, 2018 06:11 PM

    I am using windows batch script to emulate a terminated status of a job , this is to avoid creating alerts and tickets every time it ran and fail, I am looking for a way to set the exit code that will make the job status <Terminated> instead of Failure.



  • 2.  Re: what exit code should I use on my batch script to make the job go to terminated status instead of failure

    Posted Jan 03, 2018 02:58 AM

    Hi Khalid,

     

    There is no specific exit code to force a job to be in Terminated status.

    What you can do is to put this job in a Box and remove the alarm_if_fail flag on the job definition and instead set the box_terminator attribute to 1 or y.

    The box_terminator attribute statement controls whether the scheduler terminates the parent box when the job fails.

    To terminate the parent box, set the value portion of the statement to y or 1 as follows:

    • y
      Instructs the scheduler to terminate the parent box when the job ends in FAILURE.

      Note: The scheduler sends a KILLJOB event to terminate the parent box.
    • n
      (Default) Does not terminate the parent box when the job ends in FAILURE.

    In this scenario, as soon as the Job fails, the Status of its parent box will be "Terminated"

     

     

    Regards

     

    Jean Paul



  • 3.  Re: what exit code should I use on my batch script to make the job go to terminated status instead of failure
    Best Answer

    Posted Jan 04, 2018 06:47 AM

    Thank you Jean

    this is good information.

    unfortunately I do not have a box setup for this job  stream just due to the nature of the process I am working with, However I end up creating a batch that helped me resolve this issue.

    if any one wants to use it here is the script , they need to follow these steps :

    To begin we need to have the initial job that you need to make sure it will keep rerunning until it's successful lets call it "Prim_Job" , and the next job that will follow on success of the initial job ...let call it "Next_Job", the new job that you need to introduce between them is the one that will delegate the workflow to make sure the primary job is completed successfully let call it "Validator"

    the Validator job should run this command  example: : D:\Validate_me_.bat  <job_name_of _validator_Job> <Job_name_of_Primary_job> <Job_name_of_Next_job>

    make sure the success exit code is set to example: 0,1,255 with "1" or "255" is the case of exit code that you need to rerun the job at.

    make sure you run the Batch from any SQL server on the same network as your Autosys environemt

    here is the Validate.BAT script:

    REM****************Start***********************

    D:
    Set Validator=%1%
    set Prim_Job=%2%
    set Next_Job=%3%


    set TempFolder=D:\Temp
    Set TempFile=%Prim_Job%_exit_code.txt
    set statuscd=0
    set env=PRO

    CD  "%TempFolder%"
    osql -S <Autosys_SQL_Database_Server> -d -w300 -h-1 -E -Q "set nocount ON; SELECT AEDB_PRO.dbo.ujo_job_status.exit_code FROM  AEDB_PRO.dbo.ujo_job INNER JOIN AEDB_PRO.dbo.ujo_job_status ON AEDB_PRO.dbo.ujo_job.job_ver = AEDB_PRO.dbo.ujo_job_status.job_ver AND AEDB_PRO.dbo.ujo_job.joid = AEDB_PRO.dbo.ujo_job_status.joid where job_name like '%Prim_Job%'" >%TempFolder%\%TempFile%

    if {"%errorlevel%"} NEQ {"0"} (
            cd "%TempFolder%"
        set msg= Failure
         set statuscd=1
        goto endprocessing
    )
    FOR /F "delims=" %%i IN (%TempFile%) DO set pf=%%i
    echo %pf%
    if %pf% EQU 0 (set statuscd=0
    goto endprocessing
    )

    if %pf% NEQ 0 (
    D:
    CD "D:\Program Files (x86)\CA\Workload Automation AE\autosys\bin"
    sendevent -E FORCE_STARTJOB -J %Prim_Job%
    sendevent -J %Validator% -E CHANGE_STATUS -s INACTIVE
    goto retryprocessing
    )

    :retryprocessing
    sendevent -J %Validator% -E CHANGE_STATUS -s INACTIVE
    sendevent -J %Next_Job% -E JOB_ON_HOLD
    D:
    CD ..
    sleep 15
    exit /B %statuscd%
    del /Q %TempFolder%\%TempFile% 2>NUL

    :endprocessing
    sendevent -J %Next_Job% -E JOB_OFF_HOLD
    D:
    CD ..
    del /Q %TempFolder%\%TempFile% 2>NUL
    exit /B %statuscd%

     

    REM ***************************END********************************************