I'm trying to make netcat behave as a simple server, but directing its
output back to the client is inconsistent.
I'm using the named-pipe/fifo technique I've seen documented. But why
doesn't it work except with "cat", as follows?
while true;do nc -vv -l -p 5555 0< /tmp/backpipe | cat 1>
/tmp/backpipe;done
Only this works. If it receives some text from another machine
(executing e.g., echo TEST | nc <serverIP> 5555 ), it successfully
boomerangs the text back to that client machine. But if I replace
"cat" with anything else (e.g., a tr command to do character
substitutions), nc doesn't manage to send back the processed result
(even though it does get into the backpipe).
If the command is "cat" the nc output is:
[root@CHANG tmp]# while true;do nc -vv -l -p 5555 0< /tmp/backpipe |
cat 1> /tmp/backpipe;done
Listening on any address 5555
Connection from 192.168.3.2:1148
Total received bytes: 5
Total sent bytes: 5
Listening on any address 5555
Otherwise nc sends nothing back:
CHANG tmp]# while true;do nc -vv -l -p 5555 0< /tmp/backpipe | tr TES
tes 1> /tmp/backpipe;done
Listening on any address 5555
Connection from 192.168.3.2:1149
Total received bytes: 5
Total sent bytes: 0
Listening on any address 5555
In both cases the to-be-returned output *does* make it successfully
into the backpipe (a server-local "cat backpipe" shows it). In one
case it is extracted from there and returned to the client by the
original "nc" and in the other not. Why??
|