I wanted to make two pipes for a netcat server that inputs text into the server, and one that outputs text from the server. I have the server running in a seperate script with the input and output pipes. Another script (that I haven't made yet) reads the output from the netcat server using the input pipe, then sends data into the output pipe. The whole time this is happening, a client is sending data to the server, and the script I haven't made reads the data sent from the client on the server, then outputs data into the server, which goes to the client. The server script doesn't recieve data from the client when I add an output or input pipe, and it does not respond to data sent into the input pipe. I don't know why this happens, so if someone could show me how to do it, that would be great.

Server script:


mkfifo in
mkfifo out

sudo nc -lk 22 <in >out
#Yes, I know I can run this in background, but I don't
#+want to do that yet.

Client script:


while [ 1 ]
nc localhost 22
#I know this block looks odd, but it allows the client to continue
#+communicating with the server, even after an EOF.

Theoretical server handling script:

#This script is run after the server script is run in another console.

while [ 1 ]
in="$(cat out)" #The script will be stuck here until there is output from the "out" pipe
if [ $in = "blah" ]
echo "blah to you, too." >in #Here, the echo output should be sent to the client from the server
#I can add a lot more here after I get this sorted out
  • didn't you ask this question before? i know i answered a question about a networked bash and how ncat might be used to set the shell up as a server. remember? – mikeserv Jan 5 '16 at 2:29

Your Answer

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

Browse other questions tagged or ask your own question.