Adding nc -q?

Scott Maxwell dl.scottmaxwell at gmail.com
Mon Jan 15 03:16:09 UTC 2007


On 1/14/07, Rob Landley <rob at landley.net> wrote:

> On Saturday 13 January 2007 7:48 pm, Scott Maxwell wrote:
> > Thanks to all busybox developers for your really amazing software,
> > which is making it easy and painless to develop some nifty stuff to
> > run on a Linksys router under DD-WRT.
> >
> > I'm using busybox to help develop a simple watchdog script, for which
> > it would be very nice to have the functionality of "nc -q _seconds_".
> > This option causes nc to exit _seconds_ seconds after EOF.
>
> Ok, to clarify, this is N seconds after the OUTGOING EOF, without waiting for
> the incoming side to EOF?  (Could you confirm that I've got you right?  This
> is essentially a wild guess...)
>
> If so, it shouldn't be too hard to implement...

Ah-hah, in assembling an example for my reply, I realized that I made
a mistake.  What I want is not "nc -q" after all -- what I want is for
nc to exit when (and only when) the remote server socket closes, even
if nc has read EOF on its standard input.  The "real" nc does this,
but the busybox version doesn't: if you pipe something to its stdin,
the busybox version exits when it has read EOF on stdin, even if the
remote socket is still open.

What I'm trying to accomplish is for my watchdog script to be able to
do something along these lines:

echo start-monitor  |  nc remotehost port  |  blahblahblah

When I do this with the "real" nc, it does what I want: it reads its
stdin and sends that to the remote host, then reads from the server
and prints the server's output to stdout.  When the server socket
closes, nc exits, and the script can proceed past that pipeline.

By contrast, when I do this using the busybox nc, nc apparently exits
as soon as it has read all of stdin (and sent it to the server).  It
doesn't care that the remote socket is still open.

(As an aside, my memory of "nc -q" was exactly backward: in fact, "nc
-q 0" causes the real nc to do what the busybox nc always does (i.e.,
exit immediately after all of stdin is read).  So despite my original
message, what I want is basically the opposite of that: for the
busybox nc's default to be the same as the real nc's default, and stay
alive.  Of course, if there's already some way to get the busybox nc
to do what I want, that's even better!)

I apologize for my confusing mistake!

-- 
"Life results from the non-random survival of randomly varying
replicators." -- Richard Dawkins



More information about the busybox mailing list