coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Allow tail to display data after stream stops sending input after N


From: Pádraig Brady
Subject: Re: Allow tail to display data after stream stops sending input after N seconds
Date: Mon, 25 Apr 2022 13:45:32 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:97.0) Gecko/20100101 Thunderbird/97.0

On 24/04/2022 11:45, konsolebox wrote:
A command like this doesn't display data:

tail -f /var/log/messages -n +1  | grep -e something --line-buffered | tail

probably because the last tail waits for the pipe to terminate.

Right, the command line above doesn't display data,
as the final tail will wait until its input is closed,
before determining the data to display.

But this could work if there exists an option like -S which allows
tail to wait for N seconds before considering input as "stopped" and
then displaying currently absorbed input.

Current workaround would be to use a temporary file and use sleep or
maybe some repeated inotify checks before running second tail but it's
messy.

I'm not sure we need a separate option for this.
tail(1) will promptly act upon closed input,
so we can organize to close input upon a count
(with head -n, or grep -m), or after a time with timeout(1).

How about:

  timeout 10 \
  tail -f /var/log/messages -n +1 |
  grep -e something |
  tail

If that didn't suffice, you could organize things to
get the pid of a sleep process to pass to tail's --pid option:

  sleep 10 & sleep_pid=$!
  tail --pid=$sleep_pid -f /var/log/messages -n +1 |
  grep -e something |
  tail

cheers,
Pádraig



reply via email to

[Prev in Thread] Current Thread [Next in Thread]