When doing a tail -f error.log
, how to insert programmatically a line break after nothing has been appened to the file for 3 seconds ?
(obviously, once one line break has been added, no other line break should be added until other line(s) of text is added to the log file)
For instance, these lines are appened to error.log :
foo
bar
boo [[wait 4 seconds]]
2far
2foo
2bar
2boo [[wait 40 seconds]]
2far
This would be the output in the console :
foo
bar
boo
2far
2foo
2bar
2boo
2far
Best Answer
You could always implement the
tail -f
(well here, unless you uncomment theseek()
, more liketail -n +1 -f
as we're dumping the whole file) by hand withperl
for instance:Or let
tail -f
do the tailing and useperl
to insert the newlines if there's no input for 3 seconds:Those assume that the output itself is not slowed down (like when the output goes to a pipe that is not actively read).