Skip to content

Instantly share code, notes, and snippets.

@deckerego
Created October 19, 2017 19:35
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 deckerego/be3463d84e7fba10ac3c8cb67b6cc2c7 to your computer and use it in GitHub Desktop.
Save deckerego/be3463d84e7fba10ac3c8cb67b6cc2c7 to your computer and use it in GitHub Desktop.
Sleep while waiting for a TCP port to open, then execute a command
#!/bin/bash
HOST="$1"
PORT="$2"
RUNNING=1
while [[ $RUNNING -ne 0 ]]; do
echo "Waiting for $HOST:$PORT..."
sleep 3
nc -z "$HOST" "$PORT"
RUNNING=$?
done
${@:3}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment