nc -q -1 local host ${PORT} ${CMD}

In Ubuntu, nc may be used as above, with the -q option. See manpage.

  • -q after EOF on stdin, wait the specified number of seconds and then quit. If seconds is negative, wait forever.

However, this option is not available in Redhat 5. See manpage. How do I achieve the equivalent of nc -q in Redhat 5?

  • 3
    What version of netcat are you using? Did you compile from source, or install using your package manager? You might want to try compiling netcat from source, or attempting to compile the Ubuntu version on your Redhat machine. Also, it would be helpful to explain why you need this behaviour (specifically why you need to wait X seconds after EOF), as it might help to suggest alternative solutions. – Breakthrough Jun 22 '15 at 5:17

What do you want that option for? If you explain the use case, maybe we can come up with an alternative.

For example, maybe

while 1; do
    nc localhost ${PORT}

is sufficient?

I think the linux.die.net man pages is from RHEL5, but not 100% sure.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.