1

I am trying to captuer the actual error of the perl script if it fails. And its not stopping and the next script is getting triggered.

UPDATED Python scripts are running fine only having problem with the perl script

if ! perl test.pl arg2 arg1 ;   
        then
        echo "Error running test.pl in Preparing data for algorithm; rest of process stopped." >&2 >>$LOG_PATH/Perl_RUN_$TRACK_TIME

    elif ! python themes.py;
        then
        echo "Error running themes.py rest of process stopped." >&2 >>$LOG_PATH/Python_RUN_$feed_name'_'$TRACK_TIME 

    elif ! python $SCRIPT_PATH/pre_survey_dt.py;
        then
        echo "Error running pre_survey_dt.py rest of process stopped." >&2 >>$LOG_PATH/Python_RUN_$TRACK_TIME
fi

Please advice what I am missing here.

1
  • 2
    What's the question here? Nothing in that snippet is going to cause your script to exit. If you want the script to do that you need to tell it to exit. Commented Jul 15, 2015 at 12:56

1 Answer 1

2
if ! perl test.pl arg2 arg1; then
    echo "test.pl failed with error code $?" >&2
    exit 1
fi

Use return instead of exit:

  • to return from a shell function.
  • to exit from a shell script that has been sourced.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.