Skip to content

Instantly share code, notes, and snippets.

@tobstarr
Last active August 29, 2015 14:01
Show Gist options
  • Save tobstarr/59d1482837885d7240c9 to your computer and use it in GitHub Desktop.
Save tobstarr/59d1482837885d7240c9 to your computer and use it in GitHub Desktop.
#!/bin/bash
abort() {
echo $1
exit 1
}
HOST=$1
PORT=$2
TIMEOUT=$3
if [[ "$TIMEOUT" == "" ]]; then
TIMEOUT=60
fi
if [[ "$HOST" == "" ]]; then
abort "HOST not provided"
fi
if [[ "$PORT" == "" ]]; then
abort "PORT not provided"
fi
for i in $(seq 1 $TIMEOUT); do
nc -z -w1 $HOST $PORT
if [[ "$?" == "0" ]]; then
exit 0
fi
echo .
sleep 1
done
abort "timeout waiting for $HOST $PORT"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment