Last active
October 16, 2017 10:27
-
-
Save dermoumi/13715ee4f0f4c25edad2f5f61983b5bc to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# Small utility to wait for port to open. | |
# | |
# usage: | |
# ./port-wait.sh hostname port [timeout=10] | |
# | |
# ex: | |
# ./port-wait.sh 127.0.0.1 3000 | |
host=$1 | |
port=$2 | |
if [ -z "$host" ] || [ -z "$port" ]; then | |
echo "usage: ./$0 hostname port [timeout=10]" | |
exit 1 | |
fi | |
timeout=$3 | |
if [ -z "$timeout" ]; then | |
timeout=10 | |
fi | |
end_date=$(($(date +%s) + $timeout)) | |
until nc -z $host $port; do | |
sleep 1 | |
if [ "$end_date" -lt "$(date +%s)" ]; then | |
exit 1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment