Skip to content

Instantly share code, notes, and snippets.

@bjorand
Last active June 22, 2016 19:14
Show Gist options
  • Save bjorand/be911199dff69e14577fa3a97cba505d to your computer and use it in GitHub Desktop.
Save bjorand/be911199dff69e14577fa3a97cba505d to your computer and use it in GitHub Desktop.
Wait for a TCP port, Bash style
wait_tcp_port() {
local host="$1" port="$2"
# see http://tldp.org/LDP/abs/html/devref1.html for description of this syntax.
while ! exec 6<>/dev/tcp/$host/$port; do
echo "$(date) - still trying to connect to $host:$port"
sleep 1
done
exec 6>&-
}
wait_tcp_port <hostname> <port>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment