netcat still needs an input stream when receiving TCP data
The networking swiss army knife
Status: Beta
Brought to you by:
themnemonic
When running netcat in the background from a script, any attempt to connect will kill it.
Example script:
#!/bin/sh
nc -l 1337 &
When you run this, and then run:
nc localhost 1337
The original instance dies immediately, with no indication for why. However, if we do:
#!/bin/sh
tail -f /dev/null | nc -l 1337 &
Then connecting to port 1337 will work correctly, and you can see the output being echoed on the terminal.