'How to use Parallel and sequential execution of bash scripts in unix
I have 3 shell scripts a.sh, b.sh and c.sh. the scripts a.sh and b.sh are to be run parallely and script c.sh should only run if a.sh and b.sh are run successfully ( with exit code 0).
Below is my code. The parallel execution is working fine but sequential execution of c.sh is out of order. It is executing after completion of a.sh and b.sh even if both the scripts are not returning exit codes 0. Below is the code used.
#!/bin/sh
A.sh &
B.sh &
wait &&
C.sh
How this can be changed to meet my requirement?
Solution 1:[1]
#!/bin/bash
./a.sh & a=$!
./b.sh & b=$!
if wait "$a" && wait "$b"; then
./c.sh
fi
Hey i did some testing, in my a.sh i had an exit 255, and in my b.sh i had an exit 0, only if both had an exitcode of 0 it executed c.sh.
Solution 2:[2]
you can try this :
.....
wait &&
if [ -z "the scripts a.sh or any commande u need " ]
then
#do something
C.sh
fi
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | yassir ait el aizzi |
