问题
I want to use nc
as a simple TCP/IP server. So far I run it using:
$ nc -k -l 3000 > temp.tmp
This works, but writes all the received data of all connections into one single file. But, I would like to have individual files.
Basically I get this if I skip the -k
switch, but then nc
shuts down as soon as the first connection is gone.
How can I keep nc
running, but use an individual file for each incoming request? (Or, if this is not possible, is there an alternative *nix tool that is able to do this?)
Please note that I do not want to restart nc
, but I want it all with a single running instance.
PS: I know that SO doesn't allow questions on finding tools, but for me this is only the fallback in case nc
isn't able to do that by itself. So, sorry for the part in parentheses…
回答1:
On the receiver:
$ nc -p 3000 -l | tar -x
On the sender:
$ tar -c * | nc <ip_address> 3000
回答2:
Omit the -k
and run it in a loop:
n=0
while nc -l 3000 > "$n".txt ; do
n=$((n+1))
done
回答3:
I think Cronolog can help in this case
-p option you can determine the period option
Also the filewatcher utility "incron" can be used which will check logs to one file & can split to some other files
来源:https://stackoverflow.com/questions/26356646/use-nc-to-write-multiple-files-how