【问题标题】:How to limit maximum line in log file [duplicate]如何限制日志文件中的最大行数[重复]
【发布时间】: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


【解决方案1】:

好的,我认为您可以执行以下操作:

ping -c 25 google.com | tee >(split -d -b 100000 - /home/user/myLogFile.log)

【讨论】:

  • 我刚试过那个脚本,但似乎有任何错误-> >tutak@127:~$ ping -c 25 google.com | sudo tee >(split -d -b 100000 myLogFile.log) >tee: /dev/fd/63: 没有这样的文件或目录我手动创建了文件,但仍然有错误
  • 我忘记了'-' - 请再试一次
  • @MuhammadJendroYuwono 您不能在命令中添加“sudo”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-22
  • 2010-12-08
  • 1970-01-01
  • 1970-01-01
  • 2018-03-14
  • 1970-01-01
相关资源
最近更新 更多