[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: netcat in listen mode don't exit



On Fri, Feb 13, 2009 at 07:26:50AM -0300, Paulo Brito wrote:
> >
> > If you want to just what's changed in the log file since the last time
> > you connected, look at the package logtail.
> >
> > For example you might run this command:
> >
> > while :; do nc -l -p 5558 -c "logtail /var/log/syslog"; done
> >
> > This would have nc exit when it's done dumping /var/log/syslog and the
> > next time someone connects it should pick up where it left off.
> >
> > Regards,
> > Tod Detre
> >
> >
> Nice tip, Tod. But the idea was keeping a connection open, to get client
> informed by server that something happened.
> 
> Anyway, looking in netcat sources yesterday I found the reason of that
> behavior. It uses the "execl" system call to run -e program (the version I
> looked don't have -c anymore). Execl just substitute the current process
> with the new one, and execl never returns! So netcat sets up the network
> connections and pipes and go off the scenes. And so, netcat got no chances
> of killing the -e program. That's the reason why when -e program exits, the
> connection is gone. In my specific case, thare's another issue: tail -f dont
> care about stdin and never returns.
> 
> Maybe someday a new feature appers in netcat: run -e/-c program in a fork or
> something, so netcat can still have the control.

If you're running this as a service, you might want to just set it up in inetd.
Assuming you're using inetd and not xinetd or others, your line might look
something like this:

5558  stream  tcp nowait  root  /usr/bin/tail tail -F /var/log/syslog

I haven't tried that, nor have I tested that it does what you want.  But it may
be worth a shot.  I've never tried putting a command that wasn't designed for
inetd in its config before.  If you try it I'm curious how it ends up working
for you.

Cheers,

-- 
Eric Gerlach, Network Administrator
Federation of Students
University of Waterloo
p: (519) 888-4567 x36329
e: egerlach@feds.uwaterloo.ca


Reply to: