【发布时间】:2016-01-05 10:33:53
【问题描述】:
给定一个运行 ping -c 25 google.com | tee /home/user/myLogFile.log 的 bash 脚本
而输出文件/home/user/myLogFile.log 包含:
PING google.com (117.102.117.238) 56(84) bytes of data.
64 bytes from 117.102.117.238: icmp_seq=1 ttl=61 time=12.7 ms
64 bytes from 117.102.117.238: icmp_seq=2 ttl=61 time=61.1 ms
(...)
64 bytes from 117.102.117.238: icmp_seq=25 ttl=61 time=7.11 ms
--- google.com ping statistics ---
25 packets transmitted, 25 received, 0% packet loss, time 24038ms
rtt min/avg/max/mdev = 5.573/11.293/61.102/11.210 ms
如何限制日志文件中的最大行数,如果达到最大值,文件将被重置并保存下一个输出?
【问题讨论】:
-
谢谢 S.Spieker,我之前已经使用过该链接。但是,它不像我想要的那样工作。像
my_program | dd bs=1 count=100 > log这样的脚本只需将文件制作到 100 字节,而不是恢复“my_program”问候 -
实际上,在上述建议的副本中有
my_program | tee >(split -d -b 100000 -)作为接受的答案
标签: bash unix ubuntu logging tee