shellautosys

How to make my currently running Autosys Job to FA [Failure] , when command script fails


I have a script which is in Autosys Job : JOB_ABC_S1

command : /ABC/script.sh

Scrpt.sh code

grep -w "ABC" /d/file1.txt

status=$?

if [ $status -eq 0 ]
then 
    echo "Passed"
else
    echo "Failed"
    exit 1
fi 

My issue is even if the script failed or pass , the AutoSys job is marked as SU SUCCESS

I don't want it to mark it as success , if script fail's .. it should mark AutoSys as FA and if script pass then mark job to SU SUCCESS

What should i change in the script to make it happen ?

Job :

insert_job : JOB_ABC_S1
machine : XXXXXXXXXXX
owner : XXXXXXXX
box_name : BOX_ABC_S1
application : XXXX
permission : XXXXXXXXXXX
max_run_alarm : 60
alarm_if_fails : y
send_notification : n
std_out_file :  XXXXX
std_err_file :  XXXXX
command :  sh /ABC/script.sh

Solution

  • At first look all seems to be fine.

    However, i would suggest a script modification which you can try out. By default Autosys fails the jobs if the exit code is non-zero unless specified.

    JOB JIL seems to be fine.

    Please update your script as below and check for 2 things:

    1. Executed job EXIT-CODE: either it should be 1 or 2. We are trying to fail the job in both the cases.
    2. Str log files

    Script:

    #!/bin/sh
    srch_count=$(grep -cw ABC /d/file1.txt)
    if [ $srch_count -eq 0 ]; then
        echo "Passed"
        #exit 0 
        exit 2
    else
        echo "Failed"
        exit 1
    fi
    

    This way we can confirm if the exit code is correctly being captured by Autosys.