I want to open a port and listen for a command, and when that command comes in, immediately run a script.
The best I've come up with is (the echo is a substitute for my script):
nc -lk 9999 | grep -q runcommand && echo "running command"
, then I run this to test:
echo runcommand | nc localhost 9999
Unfortunately it only seems to echo the text on the second time I send "runcommand"??
How can I make grep exit immediately, so my script will run immediately?