diff --git a/bind-input b/bind-input index 296f42d..8379c41 100755 --- a/bind-input +++ b/bind-input @@ -37,8 +37,8 @@ touch $BUFFER; ( echo " > binding port $IN_PT to $BUFFER"; + trap "kill -9 $NC_PID 2>/dev/null; exit 1;" HUP INT KILL TERM; - trap "kill -9 $NC_PID 2>/dev/null" INT KILL; infail=0; # (1) kill script after 10 failures @@ -61,7 +61,7 @@ touch $BUFFER; # (5) Bind input infail="0"; - ( nc -lp $IN_PT >> $BUFFER 2>/dev/null )& + nc -lp $IN_PT >> $BUFFER 2>/dev/null& NC_PID=$!; wait $NC_PID; @@ -74,10 +74,13 @@ LOOP_PID=$!; # (2) Remove buffer + kill loop # on_exit(){ echo " < closing binding port $IN_PT to $BUFFER"; - rm $BUFFER 2>/dev/null; - kill -9 $LOOP_PID 2>/dev/null; + rm $BUFFER 2>/dev/null && echo " < $BUFFER deleted"; + + kill -INT $LOOP_PID 2>/dev/null; + + exit 1; } -trap "on_exit;" INT KILL; +trap "on_exit;" HUP INT KILL TERM; wait $LOOP_PID; diff --git a/bind-output b/bind-output index 46c1d80..2ee442b 100755 --- a/bind-output +++ b/bind-output @@ -37,8 +37,8 @@ touch $BUFFER; #--------------------------------------------------------# ( echo " > binding $BUFFER to $OUT_IP:$OUT_PT"; + trap "kill -9 $NC_PID 2>/dev/null; exit 1;" HUP INT KILL TERM; - trap "kill -9 %1 2>/dev/null" INT KILL; outfail=0; # (1) kill script after 10 failures @@ -61,8 +61,9 @@ touch $BUFFER; # (5) Bind output outfail="0"; - ( tail -f $BUFFER | nc $OUT_IP $OUT_PT 2> /dev/null )& - wait $!; + tail -f $BUFFER | nc $OUT_IP $OUT_PT 2> /dev/null & + NC_PID=$!; + wait $NC_PID; done; @@ -73,10 +74,13 @@ LOOP_PID=$!; # (2) Remove buffer + kill loop # on_exit(){ echo " < closing binding from $BUFFER to $OUT_IP:$OUT_PT"; - rm $BUFFER 2>/dev/null; - kill -9 $LOOP_PID 2>/dev/null; + rm $BUFFER 2>/dev/null && echo " < $BUFFER deleted"; + + kill -INT $LOOP_PID 2>/dev/null; + + exit 1; } -trap "on_exit;" INT KILL; +trap "on_exit;" HUP INT KILL TERM; wait $LOOP_PID;