From d0b9d1b149a6957bbb2e136988801e67153244ca Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 30 Jan 2018 19:37:00 +0100 Subject: [PATCH] fix: actual 'failures' management (.5s between each failure + stop after 10 consecutive ones) + on success do as usual --- bind-output | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/bind-output b/bind-output index ff9ea6b..c62baef 100755 --- a/bind-output +++ b/bind-output @@ -41,12 +41,25 @@ touch $BUFFER; outfail=0; # (1) kill script after 10 failures -. while [ $outfail -lt 10 ]; do + while [ $outfail -lt 10 ]; do # (2) bind socket to buffer echo "(.) binding $BUFFER to $OUT_IP:$OUT_PT"; - ( tail -f $BUFFER | nc $OUT_IP $OUT_PT 2> /dev/null && outfail="0" || ( outfail=`expr $outfail + 1`; exit 1 ) || echo " * cannot access $OUT_IP:$OUT_PT" )& + # (3) Check if port open + nc $OUT_IP $OUT_PT < /dev/null; + PORT_CLOSED=$?; + + # (4) Manage taken port # + if [ "$PORT_CLOSED" -eq "1" ]; then + outfail="`expr $outfail + 1`"; + sleep .5; + continue; + fi; + + # (5) Bind output + outfail="0"; + ( tail -f $BUFFER | nc $OUT_IP $OUT_PT 2> /dev/null || echo " * cannot access $OUT_IP:$OUT_PT" )& wait $!; done;