I have a remote raspberrypi that uses autossh to connect to my local machine (with reverse tunnel -R). This should feed a dump1090 instance on my local machine. I'm using

/bin/nc localhost 40005 | /bin/nc localhost 30104

and it works great until the connection is good but when the link breaks the new connection isn't established. How can I make the netcat link persistent? Thanks!


Kind of a hacky option, but you could just wrap your nc command(s) in a while loop:

while true; do
    # your netcat command(s) here

This'll keep re-launching the netcat stuff until you kill the script.

  • 1
    You might want a sleep 1 in the loop too, to stop the loop running away on failure. – roaima Dec 9 '18 at 9:52
  • The main problem with this is that the netcat instance isn't killed when the link breaks, it just hangs. – Pavel T Dec 9 '18 at 12:26

It was solved with socat utility. Thanks to all!

/usr/bin/socat -u TCP:localhost:40005 TCP:localhost:30104

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.