Use nc to write multiple files - how?

I want to use nc

as a simple TCP / IP server. So far I am running it using:

$ nc -k -l 3000 > temp.tmp

      

This works, but it writes all received data of all connections to one file. But I would like to have separate files.

Basically I get this if I skip the switch -k

, but then nc

shut down as soon as the first connection goes away.

How can I save nc

but use a separate file for each incoming request? (Or, if this is not possible, is there an alternative * nix tool that can do this?)

Note that I do not want to restart nc

, but I want to have it all with one running instance.

PS: I know SO does not resolve tool search questions, but for me this is only a fallback case if nc

it cannot do it on its own. So sorry for the parenthesis part ...

0


source to share


3 answers


On the receiver:

$ nc -p 3000 -l | tar -x

      



Sent by:

$ tar -c * | nc <ip_address> 3000

      

+2


source


Omit -k

and run it in a loop:



n=0
while nc -l 3000 > "$n".txt ; do
   n=$((n+1))
done

      

0


source


I think Cronolog can help in this case

-p you can specify the period option

The filewatcher "incron" utility can also be used, which will check the logs for one file and may split into some other files.

0


source







All Articles