Last active
December 30, 2015 12:12
-
-
Save Kein1945/3d4e30aa299a31c1f675 to your computer and use it in GitHub Desktop.
Simple bash script that waiting hosts in environment. Usable with docker compose, when some containers not started and we doesn't have some host in environment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
hosts=( "$@" ) | |
total_hosts=${#hosts[@]} | |
while : | |
do | |
l_hosts=( ${hosts[@]} ) | |
for i in ${!l_hosts[@]} | |
do | |
host=${l_hosts[$i]} | |
if [[ $(ping $host -c 1 -W 1 2>&1 | grep unknown) ]]; | |
then | |
: | |
else | |
# Host success | |
total_hosts=$(expr $total_hosts - 1) | |
hosts[$i]="" | |
fi | |
done | |
if [[ 0 -ne $total_hosts ]]; | |
then | |
sleep 0.4 | |
else | |
exit 0 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: