fix: actual 'failures' management (.5s between each failure + stop after 10 consecutive ones) + on success do as usual

This commit is contained in:
xdrm-brackets 2018-01-30 19:37:00 +01:00
parent 0d653e20f7
commit d0b9d1b149
1 changed files with 15 additions and 2 deletions

View File

@ -41,12 +41,25 @@ touch $BUFFER;
outfail=0; outfail=0;
# (1) kill script after 10 failures # (1) kill script after 10 failures
. while [ $outfail -lt 10 ]; do while [ $outfail -lt 10 ]; do
# (2) bind socket to buffer # (2) bind socket to buffer
echo "(.) binding $BUFFER to $OUT_IP:$OUT_PT"; 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 $!; wait $!;
done; done;