KWJ2104
KWJ2104

Reputation: 2009

Netcat not Working

I'm just beginning to work with bash scripts and I've tried to get a simple pipe to work:

#!/bin/sh                                                                                   

mkfifo apipe
cat apipe | nc -l $1 | /home/matt/testprogram > apipe

Given that the port number works and the program works as I want it to, what could be making this script mess up?

My program is supposed to print some text as well as take in some user input using fgets. When I run my shell script, I want it to act like as if I was just running the program normally. When I run it I just get it blanking out and not doing anything, and I have to break it with ctrl+C.

I type into the terminal something like:

sh testnc.sh 2342

Thanks for any advice

Upvotes: 0

Views: 2171

Answers (1)

Jericon
Jericon

Reputation: 5192

You are using NC wrong. nc -l $1 is listening for an external connection on that port. So you could run something like this:

host 1:

nc -l <port> | /home/matt/testprogram

host 2:

cat files | nc <host1> <port>

But the usage that you are doing makes no sense.

Upvotes: 2

Related Questions