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?

roy
  • 45
  • 4

1 Answers1

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
Darkman
  • 2,941
  • 2
  • 9
  • 14
  • 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 – roy May 11 '21 at 06:47