Automic Workload Automation

  • 1.  How to exit from a UNIX job without losing the job messenger footer in the report?

    Posted Feb 17, 2016 10:24 AM
    I have noticed that if a UNIX job contains ends due to an exit statement, the job messenger footer will be missing from the job report. Is there a way around this?


  • 2.  How to exit from a UNIX job without losing the job messenger footer in the report?

    Posted Feb 17, 2016 10:37 AM
    I'm assuming you are putting the actual UNIX commands in the Process tab and not just executing a script.  I've seen this before and I had thought that there was a way to do this.  Rafael_Lubera_1451  might know / remember.

    I don't think it hurts anything though.  Do you just want the footer there for the date / time information?


  • 3.  How to exit from a UNIX job without losing the job messenger footer in the report?

    Posted Feb 17, 2016 10:39 AM
    Laura Albrecht said:
    I'm assuming you are putting the actual UNIX commands in the Process tab and not just executing a script. ...
    I don't think it hurts anything though.  Do you just want the footer there for the date / time information?
    That’s right. I just assumed that there was a standard approach to this sort of thing.


  • 4.  How to exit from a UNIX job without losing the job messenger footer in the report?

    Posted Feb 17, 2016 10:49 AM
    If I enable extended reports, and look at the JCL tab of the job report, I see that there are some lines at the bottom of the script, right after the last script statement from the Process:
    ##UC4[sh]/opt/uc4/agent/bin/ucxjlx6m MNR=0100 IPA=10.51.20.193 JNR=0043900582 PNR=22160 TYP=E RET=$? TXT="        Job ended" TRC=1
    ##UC4[ksh]/opt/uc4/agent/bin/ucxjlx6m MNR=0100 IPA=10.51.20.193 JNR=0043900582 PNR=22160 TYP=E RET=$? TXT="        Job ended" TRC=1
    ##UC4[csh]/opt/uc4/agent/bin/ucxjlx6m MNR=0100 IPA=10.51.20.193 JNR=0043900582 PNR=22160 TYP=E RET=$status TXT="        Job ended" TRC=1
    ##UC4[tcsh]/opt/uc4/agent/bin/ucxjlx6m MNR=0100 IPA=10.51.20.193 JNR=0043900582 PNR=22160 TYP=E RET=$status TXT="        Job ended" TRC=1
    ##UC4[bash]/opt/uc4/agent/bin/ucxjlx6m MNR=0100 IPA=10.51.20.193 JNR=0043900582 PNR=22160 TYP=E RET=$? TXT="        Job ended" TRC=1

    I am not familiar with how the agent processes these lines, but I presume they have special meaning, and are used by the agent to run the job messenger and insert the footer into the job report.



  • 5.  How to exit from a UNIX job without losing the job messenger footer in the report?
    Best Answer

    Posted Feb 17, 2016 05:46 PM
    I've found if you put the exit statement in parentheses, it works as you wish. However, I believe the parentheses mean something specific to the shell script (like "don't totally exit here" or something), so it could have unintended consequences if you are dealing with complex loops.

    (exit 0)


  • 6.  How to exit from a UNIX job without losing the job messenger footer in the report?

    Posted Feb 18, 2016 01:08 AM

    Option 1: work with a function

    export ref="1"
    function myStuff {
    if [ "0" != "$ref" ]; then return 1; fi
    return 0
    }
    myStuff

     

    Option 2: work with a subshell, might be added in HEADER  / FOOTER..

    (
    export ref="1"

    if [ "0" != "$ref" ]; then exit 1; fi
    exit 0
    )

    Doing only a (exit 123) will spawn a subshell and immediately exit. It will only set the return code but not stop the script processing.



  • 7.  How to exit from a UNIX job without losing the job messenger footer in the report?

    Posted Feb 18, 2016 03:35 AM
    I've found if you put the exit statement in parentheses, it works as you wish. However, I believe the parentheses mean something specific to the shell script (like "don't totally exit here" or something), so it could have unintended consequences if you are dealing with complex loops.

    (exit 0)
    Running the exit from inside a subshell does the trick. This sets the value of the special variable $? without skipping any subsequent commands that the agent may insert into the script. Then the Job Messenger uses that variable to do its thing. Thanks, JessicaIsaacson603938 !

    Here is an example based on my script:
    #!/bin/bash
    # Do the stuff that the script is supposed to do, and set the return code
    # with which the script should exit in the variable final_rc.

    some_command
    final_rc=$?

    if [[ $final_rc -eq 0 ]]; then
      echo "INFO: Exiting with RC ${final_rc}."
    else
      echo "ERROR: Exiting with RC ${final_rc}." 
    fi

    (exit $final_rc)