...
1#!/bin/bash
2
3set -e -u
4
5wait_tcp_port() {
6 local host="${1}" port="${2}"
7
8 # see http://tldp.org/LDP/abs/html/devref1.html for description of this syntax.
9 local max_tries="40"
10 for n in `seq 1 "${max_tries}"` ; do
11 if { exec 6<>/dev/tcp/"${host}"/"${port}" ; } 2>/dev/null ; then
12 break
13 else
14 echo "$(date) - still trying to connect to ${host}:${port}"
15 sleep 1
16 fi
17 if [ "${n}" -eq "${max_tries}" ]; then
18 echo "unable to connect"
19 exit 1
20 fi
21 done
22 exec 6>&-
23 echo "Connected to ${host}:${port}"
24}
25
26wait_tcp_port "${1}" "${2}"
27shift 2
28exec "$@"
View as plain text