0

In bash file myBig.sh I call another two bash files like this:

/bin/bash myBuildShortServer.sh
/bin/bash myStart.sh

It's work... but has one problem. I want to start myStart.sh only after success execute myBuildShortServer.sh.

Content of myBuildShortServer.sh is this:

mvn install -Pruntime -DskipTests=true -f pom-server.xml

The bash file myBuildShortServer.sh just start maven tasks (goals). And when success finish tasks print in console smt like this:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  30.254 s
[INFO] Finished at: 2022-06-06T12:05:43+03:00
[INFO] ------------------------------------------------------------------

So I need to start myStart.sh ONLY after myBuildShortServer.sh success finish.

Is it possible?

2 Answers 2

2

If the first script is only this line you can try something like:

 myBuildShortServer.sh && myStart.sh

Of course you should make the scripts executable:

chmod +x <name of the scripts>
1

Add to myBuildShortServer.sh a code to set the error code of the script with the bash exit command, to propagate the error code returned by mvn, like this:

mvn install ...
rc=$?
if [ $rc -ne 0 ] ; then
  echo Could not perform mvn install, exit code [$rc]; exit $rc
fi
exit 0

You could then test the error code of the first script and avoid executing the following script if it's non-zero.

2
  • If the mvn command is the last thing in the script, its exit status will propagate automatically. It's only if the script is more complicated that you need to add error handling logic. Commented Jun 6, 2022 at 14:49
  • Any way to find error message similar to error code you did with $?
    – c.sankhala
    Commented May 8 at 13:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .