Using netcat/cat in a background shell script (How to avoid Stopped (tty input)? )
you probably want netcat's "-d" option
, which tells it not to read from STDIN
.
I can confirm that -d
will help netcat run in the background.
I was seeing the same issue with:
nc -ulk 60001 | nc -lk 60002 &
Every time I queried the jobs
, the pipe input would stop.
Changing the command to the following fixed it:
nc -ulkd 60001 | nc -lk 60002 &
Are you sure you've given your script as is or did you just type in a rough facsimile meant to illustrate the general idea? The script in your question has many errors which should prevent it from ever running correctly, which makes me wonder.
The spaces around the
=
incatpid=$!
make the line not a valid variable assignment. If that was in your original script I am surprised you were not getting any errors.The
kill catpid
line should fail because the literal wordcatpid
is not a valid job id. You probably wantkill "$catpid"
.
As for your actual question:
cat
should be reading from/dev/charfile
and not from stdin or anywhere else. Are you sure it was attempting to read tty input?Have you tried redirecting
netcat
's input likenetcat < /dev/null
if you don't neednetcat
to read anything?