Skip to content
Advertisement

How to make a “same response” server with bash?

I’m trying to set up a simple server that returns always the same response.

Based on this question I’ve tried to use

ncat -l 2000 --keep-open --exec "/bin/echo 234"

but on the client it shows only once.

Ncat: Broken pipe.

If I use the UDP option (-u), it works as intended. So I’m guessing it’s EOF’s fault.

Is there a way to make it work as a reponse to the client’s messages in TCP?

Advertisement

Answer

For something as simple you could:

ncat -l 2000 --keep-open --exec "xargs -I{} echo 234"

I find also the following works:

ncat -l 2000 --keep-open --sh-exec "while read line; do echo 234; done"

or like:

ncat -l 2000 --keep-open --sh-exec "echo 234; cat >/dev/null"
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement