From nobody Tue Apr 04 07:25:36 2023 X-Original-To: questions@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PrK6v2pWBz43786 for ; Tue, 4 Apr 2023 07:25:43 +0000 (UTC) (envelope-from freebsd-questions-3@voidcaptain.com) Received: from mx3.mx00.net (mx3.mx00.net [IPv6:2600:3c01::f03c:91ff:fe89:a3f5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature ECDSA (P-256) client-digest SHA256) (Client CN "mx3.mx00.net", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PrK6v0tFfz3NX1 for ; Tue, 4 Apr 2023 07:25:43 +0000 (UTC) (envelope-from freebsd-questions-3@voidcaptain.com) Authentication-Results: mx1.freebsd.org; none Received: from razz.mx00.net [2600:3c01::f03c:91ff:fed5:a231] by mx3.mx00.net with ESMTP id 20230329-1pjb2v-0002eC-36; Tue, 04 Apr 2023 07:25:37 +0000 Message-ID: <4b563b2a-2c26-8c84-f8db-51e4f17dcaf6@slagle.net> Date: Tue, 4 Apr 2023 00:25:36 -0700 List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 Subject: Re: Clogged pipe? Content-Language: en-US To: Matthias Apitz Cc: Christian Weisgerber , questions@freebsd.org References: From: Pete In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4PrK6v0tFfz3NX1 X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:63949, ipnet:2600:3c01::/32, country:SG] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N Matthias Apitz wrote on 4/3/23 22:36: > El día lunes, abril 03, 2023 a las 08:38:15 -0700, Pete escribió: > >> So, I guess the short answer is that cat -n does block buffering to the >> pipe, but cat with no options does not. >> >> tail -f testfile | cat | sed -u 's/^/X/' >> tail -f testfile | cat -u | sed -u 's/^/X/' >> tail -f testfile | cat -nu | sed -u 's/^/X/' >> >> all provide immediate output, but >> >> tail -f testfile | cat -n | sed -u 's/^/X/' >> >> does not and waits. > i.e. the sed(1) and the cat(1) are just reading STDIN waiting for > more input to appear. The problem is with the "tail -f" > The -f flag let the tail(1) after it has read all the lines of > "testfile" just waiting for the file cwto grow which > could happen if other processes would write to the file. > > Nothing magic, wrong usage of -f here. Well, I was just showing a simplified example to illustrate the problem; what I was really trying to script is this: /usr/bin/tail -f -n+1 /var/log/exim/main-$(/bin/date -u '+%Y%m%d').log | /bin/cat -n | /usr/bin/sed -Eu 's/^[[:blank:]]*([[:digit:]]*)[[:blank:]]+/\1 /' which prefixes line numbers as it watches today's exim log file scroll along. So, in this case the -f flag is needed on the tail command. What actually fixes the buffering problem on FreeBSD (it already works fine on Linux) is to add the -u flag to the cat command.