From 36baf32e9ed18cf1819101d18b671aad7baafb0a Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Sun, 3 Oct 2021 05:40:00 -0300 Subject: [PATCH] Add netcat support from command line --- wait-for-it.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/wait-for-it.sh b/wait-for-it.sh index d990e0d..e265009 100755 --- a/wait-for-it.sh +++ b/wait-for-it.sh @@ -15,6 +15,7 @@ Usage: Alternatively, you specify the host and port as host:port -s | --strict Only execute subcommand if the test succeeds -q | --quiet Don't output any status messages + -nc | --netcat Force to use netcat instead of bash tcp detection -t TIMEOUT | --timeout=TIMEOUT Timeout in seconds, zero for no timeout -- COMMAND ARGS Execute command with args after the test finishes @@ -32,7 +33,7 @@ wait_for() WAITFORIT_start_ts=$(date +%s) while : do - if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then + if [[ $WAITFORIT_ISBUSY -eq 1 ]] || [[ $WAITFORIT_NETCAT -eq 1 ]]; then nc -z $WAITFORIT_HOST $WAITFORIT_PORT WAITFORIT_result=$? else @@ -85,6 +86,10 @@ do WAITFORIT_QUIET=1 shift 1 ;; + -nc | --netcat) + export WAITFORIT_NETCAT=1 + shift 1 + ;; -s | --strict) WAITFORIT_STRICT=1 shift 1 @@ -140,6 +145,7 @@ WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15} WAITFORIT_STRICT=${WAITFORIT_STRICT:-0} WAITFORIT_CHILD=${WAITFORIT_CHILD:-0} WAITFORIT_QUIET=${WAITFORIT_QUIET:-0} +export WAITFORIT_NETCAT=${WAITFORIT_NETCAT:-0} # Check to see if timeout is from busybox? WAITFORIT_TIMEOUT_PATH=$(type -p timeout)