[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-wget] wget in a 'dynamic' pipe
From: |
Tim Rühsen |
Subject: |
Re: [Bug-wget] wget in a 'dynamic' pipe |
Date: |
Tue, 11 Sep 2018 09:43:12 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 |
On 9/11/18 5:34 AM, Dale R. Worley wrote:
> Paul Wagner <address@hidden> writes:
>> Now I tried
>>
>> { i=1; while [[ $i != 100 ]]; do echo
>> "http://domain.com/path/segment_$((i++)).mp4"; done } | wget -O foo.mp4
>> -i -
>>
>> which works like a charm *as long as the 'generator process' is finite*,
>> i.e. the loop is actually programmed as in the example. The problem is
>> that it would be much easier if I could let the loop run forever, let
>> wget get whatever is there and then fail after the counter extends to a
>> segment number not available anymore, which would in turn fail the whole
>> pipe.
>
> Good God, this finally motivates me to learn about Bash coprocesses.
>
> I think the answer is something like this:
>
> coproc wget -O foo.mp4 -i -
>
> i=1
> while true
> do
> rm -f foo.mp4
> echo "http://domain.com/path/segment_$((i++)).mp4" >&$wget[1]
> sleep 5
> # The only way to test for non-existence of the URL is whether the
> # output file exists.
> [[ ! -e foo.mp4 ]] && break
> # Do whatever you already do to wait for foo.mp4 to be completed and
> # then use it.
> done
>
> # Close wget's input.
> exec $wget[1]<&-
> # Wait for it to finish.
> wait $wget_pid
>
> Dale
Thanks for the pointer to coproc, never heard of it ;-) (That means I
never had a problem that needed coproc).
Anyways, copy&pasting the script results in a file '[1]' with bash 4.4.23.
Also, wget -i - waits with downloading until stdin has been closed. How
can you circumvent that ?
Regards, Tim
signature.asc
Description: OpenPGP digital signature