linux里如何将一个文件和一个套接字绑定?-灵析社区

我买了30万的鞋子

简而言之,就是这个文件被输入的内容,都会被吞没,发送到套接字(IP地址和端口号的组合)的另一边去. 我在做一个指令的输出的网络的重定向,它的格式大概是`xxx -l a.log`,有一个叫a.log的输出文件作为记录. 我希望能做到,这个指令根据-l选项不断输出内容到a.log的同时,某个手段能把这些内容全都即时通过套接字传输到另一边. 甚至就不通过什么a.log,直接就有一个文件就代表着这个套接字. 肯请赐教. 我测试了nc指令的手段,把某个文件作为标准输入,进行套接字通信. 确实实现了我想要的效果,这个文件的内容被socket通信交到了另一边. 但有一个问题,那就是我在通信维持的同时继续向这个文件追加内容的话,它好像并不会把追加的内容也发过去.这种情况该怎么处理呢?

阅读量:228

点赞量:16

问AI
你需要 "tail" (https://link.segmentfault.com/?enc=hVQjrHb%2F9IbdLLngfCuRbw%3D%3D.dfZsADVvuV7t7LvXNqdpRyzdpbospBhRT%2BpmhE3hv3V8sX2bhKMi8xfKHF3vHBmLoEbgMIv4GT76yZEIsg9LDw%3D%3D) tail -f a.log | nc ...... «tail "-f, --follow[={name|descriptor}]" output appended data as the file grows; an absent option argument means 'descriptor'With --follow (-f), tail defaults to following the file descriptor, which means that even if a tail'ed file is renamed, tail will continue to track its end. This default behavior is not desirable when you really want to track the actual name of the file, not the file descriptor (e.g., log rotation). Use --follow=name in that case. That causes tail to track the named file in a way that accommodates renaming, removal and creation.»