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

Re: netcat in listen mode don't exit



2009/2/11 Michael Iatrou <m.iatrou@freemail.gr>
When the date was Wednesday 11 February 2009, Paulo Brito wrote:

> 2009/2/11 Michael Iatrou <m.iatrou@freemail.gr>
>
> > When the date was Wednesday 11 February 2009, Paulo Brito wrote:
> > >  I"m trying to setup netcat so it serves logs to other systems. When
> > > a client connects, the server starts to send some logs.
> > >
> > > I run netcat in listem mode like this:
> > >
> > > # nc -l -p 5558 -c "tail -f /var/log/syslog"
> >
> > while :; do nc -l -p 5558 -c "tail -f /var/log/syslog"; done
> >
> Michael, thanks for your reply. But if you read my entire email, you'll
> see that the problem is netcat NOT exiting after disconnect. So, your
> script will not solve the problem, because the nc never exits.

You execute ``tail -f'', which actually never returns. You may try the -w
delay option:

       # while :; do nc -l -w 10 -p 5558 -c "tail -f /var/log/syslog"; done

Please avoid top posting.

Thanks,

Thanks for de tips about top posting. I"ll remember

Michael, -w option dont make nc returns if a conection is already stablished.

I've tried this: nc -l -p 5558 -c bash. And it works! I think the big probleam is that tail doesn't connect his input stream to the data provided by nc, so it doesn't get informed when the connection comes down. As you said, tail -f never returns. Bash returns, if required. But nc would kill the -c process when the connection doesn't exists anymore... it doesn't make sense keep it running.

I'm going to try another solutions for what I want... maybe xinetd...

Thanks Michael and you all.





Reply to: