Skip to content

Instantly share code, notes, and snippets.

@Kein1945
Last active December 30, 2015 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kein1945/3d4e30aa299a31c1f675 to your computer and use it in GitHub Desktop.
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.
#!/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
@Kein1945
Copy link
Author

Usage:

./wait_until_hosts.sh mysql.dev some-other-host

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment