1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/bin/bash set -e host="$1" port="$2" shift shift cmd="$@" until echo > /dev/tcp/${host}/${port} ; do >&2 echo "${host}:${port} is unavailable - sleeping" sleep 1 done >&2 echo "${host}:${port} is up - executing command" exec $cmd