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

Re: netcat in listen mode don't exit



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.

Reply to: