1

Suppose I am 2 jar file and need to run them from shell script, i can use the below commands in the same script.

java -jar myApp1.jar

java -jar myApp2.jar

So it will start myApp1.jar first and then myApp2.jar file.

Question: I want to run myApp2.jar only if the run of myApp1.jar is successful/completed. If myApp1.jar run is failed it will exit the shell script.

Can any one please help me how can I achieve that?

0

1 Answer 1

0
java -jar myApp1.jar || exit 1 && java -jar myApp2.jar

Or

#!/bin/sh

if java -jar myApp1.jar; then
    echo 'myApp1.jar -- Successful!'
    if java -jar myApp2.jar; then
        echo 'myApp2.jar -- Successful!'
    else
        echo 'myApp2.jar -- Failed!'
        exit 1
   fi
else
    echo 'myApp1.jar -- Failed!'
    exit 1
fi
Sign up to request clarification or add additional context in comments.

1 Comment

My Complete script is something like below. But its not working. so some how I need to check if the myApp1.jar prcess completed. Right now if it fails also, myApp2.jar will execute. java -jar myApp1.jar mkdir /xyz/myapp/data if(condition){ some logic on date } touch "appData2" java -jar myApp2.jar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.