2

Given a bash script running ping -c 25 google.com | tee /home/user/myLogFile.log

And the output file /home/user/myLogFile.log containing:

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

How to limit the maximum lines in the log file, and if that maximum is reached, the file is reset and keep the next output saved?

Julien Carsique
  • 3,915
  • 3
  • 22
  • 28
  • thank you S.Spieker, I already use that link before. But, its not working like I wanted. the script like `my_program | dd bs=1 count=100 > log` just make the file until 100 Bytes and not resume the 'my_program' regards – Muhammad Jendro Yuwono Jan 05 '16 at 10:45
  • Actually, there is `my_program | tee >(split -d -b 100000 -)` as accepted answer in the above suggested duplicate – Julien Carsique Jan 06 '16 at 01:34

1 Answers1

1

Ok, I think you can do something like:

ping -c 25 google.com | tee >(split -d -b 100000 - /home/user/myLogFile.log)
Julien Carsique
  • 3,915
  • 3
  • 22
  • 28
S.Spieker
  • 7,005
  • 8
  • 44
  • 50