Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 1
    ifne tee "$target" should work fine for this Commented Jun 10, 2024 at 8:18
  • The answers listed in the dup target (including ifne tee) do not work for a command like mosquitto_sub that usually never stops. The last condition of my Q is not fulfilled: the file is written with infinite delay. Commented Jun 10, 2024 at 8:29
  • mosquitto_sub never stopping is a red herring, tee works just fine with a never-ending input (try with, say yes | tee foo if you want). Your problem is more likely that mosquitto_sub starts buffering output when output is to a pipe, and the buffer takes a long time to fill up. Try turning off the buffering with stdbuf or unbuffer, e.g. stackoverflow.com/q/11337041/2072269, unix.stackexchange.com/q/25372/70524 Commented Jun 10, 2024 at 8:45
  • I see. Apparently the buffering is indeed the issue. The question should still not be closed, because the question in the duplicate target doesn't require a solution for buffering and hence the answers there also don't include a solution. So this question differs in a significant way from the duplicate target. Commented Jun 10, 2024 at 11:30