title: How to wait till all services are up in parallel using bash?
body: <p>I have a script that starts 5 services on 4000-4004 ports.
  I want that script to be blocked till all of them are up.
  Following works for me.</p>
  
  <pre><code>while ! nc -vz localhost 4000; do sleep 1; done
  while ! nc -vz localhost 4001; do sleep 1; done
  while ! nc -vz localhost 4002; do sleep 1; done
  while ! nc -vz localhost 4003; do sleep 1; done
  while ! nc -vz localhost 4004; do sleep 1; done
  </code></pre>
  
  <p>The only problem with above is if say 4002 is still not up, it will keep on waiting for it while I have no information about 4003 &amp; 4004.</p>
  
  <p>What I would like to do is that run all of these in parallel somehow and print out status of each port. And only when all of them are up, it continues after that block else it blocks and prints out what ports are up and down.</p>
  
  <p>(Optionally I need to add some timeout as well, but that should be doable once I get how to do the above.)</p>
  
  <p>Thanks a lot.</p>
  
  <p>Edit:</p>
  
  <p>Following worked great for me:</p>
  
  <pre><code>$ parallel --timeout 300 -j0 'while ! nc -vz localhost {}; do sleep 10; done; echo {} is open' ::: {4000..4004} 5001 || { echo "One or more serves failed to start. Exiting.."; exit 1; }
  </code></pre>
  
  <p>Note: Make sure you run the following after installation. <a href="https://askubuntu.com/questions/12764/where-do-i-get-a-package-for-gnu-parallel">ref-link</a></p>
  
  <pre><code>$ sudo rm /etc/parallel/config
  </code></pre>