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?