On Fri, Apr 2, 2021 at 4:16 PM Mike Miller wrote:

> On Fri, 2 Apr 2021, gregrwm wrote:
> > From Mike Miller 26 Mar 2021 14:24:39
> >> On Thu, 25 Mar 2021, gregrwm wrote:
> >>> question for bashers:
> >>>
> >>> a bash command entered as a foreground job may fork, leave something
> >>> in the background, and exit to the bash prompt, and the job in the
> >>> background will print it's output whenever it has any.  So far so
> >>> good.
> >>>
> >>> i want to enter a command which launches 3 subcommands in parallel,
> >>> wait up to 3 seconds unless all 3 subcommands finish sooner, sort all
> >>> their output-so-far together, print it, and exit to the bash prompt at
> >>> this point, and if any of the subcommands weren't finished, leave them
> >>> in the background and let them print more output whenever they have
> >>> any.
> >>>
> >>> easy?  hard?
> >>
> >>
> >> Can you use tee to send output to a temp file?
> >>
> >> process | tee file | whatevs
> >>
> >> Data coming out of "process" will go to "file" but it will also go to
> >> "whatevs" for further processing.
> >>
> >> Then you read from file.  Mutiple processes could make multiple files.
> >> Use the temp command to make the files.  One thing I'm not completely
> >> sure of: does tee write continously to file, or does it do it in only
> >> at certain moments, like after each block of data comes out?  I'm
> >> guessing continuous but not sure.
> >>
> >> Mike
> >
> >
> > what's behind the question is asking several hosts for their list of
> > virtual guests and sorting the list together, and it would be nice to
> > come up with the sorted list right away even if one or more of the hosts
> > is down.  my current and obvious compromise just waits for all results
> > before finishing.
>
>
> If you have some idea of how many lines you'll be sorting, you should be
> able to sort that many lines into a file while waiting for the remaining
> lines.  To put the first $N lines into a temp file, do this:
>
> process | tee >(head -$N | sort > tempfile_$N) | whatevs
>
> The whole unsorted output still goes to "whatevs".  So you could string
> together a bunch of those tee commands and have them process increasingly
> more numbers of lines.  Or you could do this...
>
> process | tee tempfile | whatevs
>
> Then just do this whenever you please:
>
> sort tempfile | less
> Mike



it's a good suggestion.  what i've done with it:  toss the subcommands into
the background, tee them to a file, see the unsorted output as it arrives
on standard out, and run a second command that sorts from the file.  the
only bit still missing would be to wait either for all subcommands to
finish, or 3 seconds, whichever comes first, and then do the sort.  but
this is already good enough.  thanks!

-- 
this concludes test 42 of big bang inflation dynamics.  in the advent of an
actual universe, further instructions will be provided.
000000000000000000000042
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.mn-linux.org/pipermail/tclug-list/attachments/20210402/467aafb5/attachment.htm>