Skip to main content
1 of 3
Alexander Mills
  • 10.9k
  • 27
  • 120
  • 214

Bash listen for exit of background process

I have this bash script to start some servers:

services=(
    account-service
    reminder-service
    activity-service
    socket-service
    chat-service
    web-app
)


for s in "${services[@]}"; do

 (
   set -e;
   cd "$s"
   git pull
   echo "$cmd" | bash
 ) &

 sleep 1;

done

wait;

sometimes the git pull command will fail. But the failure is deep in the logs and not always obviously. How can I abort the whole script if one of the commands in the subshell exits with 1?

Alexander Mills
  • 10.9k
  • 27
  • 120
  • 214