0

I am new to shelll script and my question here might be very basic.

I have a script(.sh file) which is making call to couple of scipt files. now suppose, I am getting error message on execution of script 1, I would like to abort the script and completely terminate the script flow. It should not go on next step.

could you please tell me how i can achieve this.

EDIT

My scriptA is making call to Script B, which internally making call to some other scriptC.

if execution of StopServer1.py script(part of script B) failed, flow should terminate here itself and should not come to StopServer2 and StopServer3 and control goes to Script A. which should also terminate .

please let me know if set -e will help here.

cd /usr/oracle/WSAutomate/
java weblogic.WLST /usr/oracle/StopServer1.py >> $logFileName
java weblogic.WLST /usr/oracle/StopServer2.py >> $logFileName
java weblogic.WLST /usr/oracle/StopServer3.py >> $logFileName
3
  • Do you mean abort manually or programmatically? Commented Mar 25, 2014 at 9:49
  • How are you getting the error message? Via exit status code or via terminal output? Commented Mar 25, 2014 at 9:51
  • I want to abort this programmatically. Commented Mar 25, 2014 at 10:06

2 Answers 2

4

You can use:

set -e

for aborting the script on error.

main script snippet:

#!/bin/bash    
set -e

# Any failure in these script calls will make main script to exit immediately
./script1
./script2
./script3
Sign up to request clarification or add additional context in comments.

4 Comments

Hello Anubhva - thanks for your quick response. I have doubt here. my script is making call to Script B, which internally making call to some other script. if execution of StopServer1.py script failed, flow should terminate here itself and should not come to StopServer2 and StopServer3. please let me know if set -e will help here. cd /usr/oracle/WSAutomate/ java weblogic.WLST /usr/oracle/StopServer1.py >> $logFileName java weblogic.WLST /usr/oracle/StopServer2.py >> $logFileName java weblogic.WLST /usr/oracle/StopServer3.py >> $logFileName
I have just tested this option and its working to some extend. I see my script is getting aborted.. can i echo or print some message before aborting the script.. this is just for support analyst to understand what went wrong.
@kumarb do not post code in comments, it is impossible to read properly. Instead, update your question or ask a new one if it is another issue.
@kumarb: What you're looking for can be done using trap command.
0

You can use the operator && this way <execute_script1> && <execute_script2>.

It executes script1 and, only if everything goes right, it executes script2. In case of error script2 will not run.

1 Comment

Thanks but this will not solve my issue.. ! appreciate your quick response.

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.