Automic Workload Automation

Expand all | Collapse all

Unix Job not failing as I would expect even though I have "Exit 1" in my script

  • 1.  Unix Job not failing as I would expect even though I have "Exit 1" in my script

    Posted Dec 19, 2017 07:31 AM
    Hi,
     I have a Unix shell script which has completed successfully but I expected it to fail.

    I have an Exit 1 in my code 


    echo "Checking DNFS....."
       count=`sqlplus -s '/ as sysdba'<<EOF
       set pagesize 0 feedback off verify off heading off echo off
       select count(*)  from v\$DNFS_stats where nfs_read >0 or nfs_write >0;
       EOF`

       if [[ "${count}" = '0' ]]; then
          echo "DB NOT running on DNFS"
          exit 1;
       else
          echo "DB running on DNFS"
       fi
       
       #jdkv=`cat /tmp/$1_jdkver.log`
       jdkcnt=`cat /tmp/$1_jdkver.log|wc -l`
       jdkver=`expr $jdkcnt`
       if [ $jdkver -eq 1 ]; then
          echo "Java working query passed"
       else
          echo "Java working query failed, Please check JAVA"
          exit 1;
       fi

    When I run the Job, it's getting to this place in the code and exiting, but not failing.


    awos96ulnqn5.pnghttps://us.v-cdn.net/5019921/uploads/editor/8p/awos96ulnqn5.png" width="808">

    I have done a little test myself with a simple unix Job I created with only this code

    7mm4qhcic2ia.pnghttps://us.v-cdn.net/5019921/uploads/editor/7a/7mm4qhcic2ia.png" width="482">

    When I called from Automic, it behaved as I expected, job failed.

    mm666odreb7o.pnghttps://us.v-cdn.net/5019921/uploads/editor/sd/mm666odreb7o.png" width="520">


    Has anyone seen this behavior before?

    John.



  • 2.  Unix Job not failing as I would expect even though I have "Exit 1" in my script

    Posted Dec 19, 2017 02:19 PM
    JohnO'Mullane 
    If you create a shell script for the first script and execute it from the command line, what is the return code?
    For example:

    ./youscript

    Then, execute:
    echo $?


  • 3.  Unix Job not failing as I would expect even though I have "Exit 1" in my script

    Posted Dec 19, 2017 03:14 PM
    just a silly idea:

    use EXIT 1; instead of exit 1;

    stolen here:
    https://unix.stackexchange.com/questions/240723/exit-trap-in-dash-vs-ksh-and-bash



  • 4.  Unix Job not failing as I would expect even though I have "Exit 1" in my script

    Posted Dec 20, 2017 03:56 AM
    Thanks bobby_tamayo_automic FrankMuffke

    Will try both those suggestions. 
    Might be a few days before I get to test as it's not simple to reproduce the scenario in question.



  • 5.  Unix Job not failing as I would expect even though I have "Exit 1" in my script

    Posted Dec 20, 2017 08:34 AM
    Hello JohnO'Mullane

    You may have found proof for this:
     
    https://community.automic.com/discussion/comment/33567#Comment_33567

    Regards, Matthias



  • 6.  Unix Job not failing as I would expect even though I have "Exit 1" in my script

    Posted Dec 20, 2017 09:17 AM
    Thanks MatthiasSchelp

    Carsten_Schmitz_7883
    I have read your article below a couple of time but still not 100% clear.

    https://community.automic.com/discussion/comment/33567#Comment_33567

    Are you saying that the behavior I am seeing is intended functionality?



  • 7.  Unix Job not failing as I would expect even though I have "Exit 1" in my script

    Posted Dec 20, 2017 10:17 AM
    Well, good luck with that. I'm pretty certain he won't answer you the next few days :smile:.

    To make it short. What he means is that it could happen that Automic does not fetch the return code properly when you use "exit" or "exit 1".

    Matthias


  • 8.  Unix Job not failing as I would expect even though I have "Exit 1" in my script

    Posted Dec 20, 2017 10:47 AM
    provocative question:

    why does it work _always_ in unix jobs that use bash?

    ... as long as I could observe this....


  • 9.  Unix Job not failing as I would expect even though I have "Exit 1" in my script

    Posted Dec 20, 2017 11:20 AM
    :p Thats why I said we may have found proof for this.


  • 10.  Unix Job not failing as I would expect even though I have "Exit 1" in my script

    Posted Dec 20, 2017 01:05 PM
    ahhhhh [shining bulb emoticon]
    sry, fingers were faster than brain....


  • 11.  Unix Job not failing as I would expect even though I have "Exit 1" in my script

    Posted Jan 02, 2018 05:26 AM
    Well, good luck with that. I'm pretty certain he won't answer you the next few days :smile:.
    Sorry, was gone there for a while, saving the galaxy. Or on christmas holiday. One of these.

    JohnO'Mullane the post is intended to point out that the "Job messenger" doesn't get triggered when you use "exit" in your shell script. Our Automic consultant said to this: "don't use "exit" in your scripts". I kinda take that as the official Automic statement, but I find it rather limiting.

    From my tests (and Wolfgangs), using "exit" does not prevent the parsing of exit codes. Something that exits with "exit 1" should show up as ENDED_NOT_OK in Automic, and it did many times for me, in practice. So I don't think that what I describe in the article is to blame.

    But it's not entirely inconceivable that, under some circumstances, the lack of calls to the "job messenger" might cause this, e.g. when using different shells, so MatthiasSchelp is abolutely right in pointing out the possibility.

    If you can still recreate the problem, and want to get to the bottom of it, you could use the trap approach I outlined further down in the post you linked. That way, you can "exit 1" and call the job messenger, so you could rule out whether the lack of a job messenger call is the culprit of the strange behaviour you saw.

    Hope this helps.


  • 12.  Unix Job not failing as I would expect even though I have "Exit 1" in my script

    Posted Jan 02, 2018 05:46 AM
    Thanks Carsten_Schmitz_7883

    A lot of our scripts (well, the scripts are not owned by us but are owned by the applications folk who use Automic) do have Exit 1's and work as expected. I haven't seen Automic not handle these Exit codes before.

    Maybe this is a once off.

    It won't be easy to reproduce I would imagine but will try and updates with findings.