Emulating netcat -e

user787935 picture user787935 · Jun 7, 2011 · Viewed 13.6k times · Source

How can I emulate netcat -e with a version of netcat that does not have the -e option ?

I need to trigger a command remotely. I can do it with netcat - without -e:

#!/bin/bash

netcat -l 8080 ; myCommand.sh

That would do the trick, but I would like to reply to the client depending on the success or failure of the command (to have a kind of REST - like interface).

How could I do that ?

Thanks!

Answer

Jocko picture Jocko · Nov 17, 2011
mkfifo foo
nc -lk 2600 0<foo | /bin/bash 1>foo

Then just nc servername 2600 and ./script.sh

kill the client with ctrl+c