How to cancel wget download after 1%?

I am running a video download test and automating that. I wanna know how to stop a wget download session when downloads reached 1%

Thanks in advance,
Tamil

In case it's useful information to you, curl supports byte ranges, so you can tell it that you only want x number of bytes and that's it.

Regards,
Alister

If it would still be useful, it'd be simpler to terminate wget after so many seconds than to wait for 1% completion.

wget ... &

sleep 10

kill $!
wait

Another hack is piping wget into dd, using dd to limit the byte count.

Regards,
Alister

1 Like

Thanks all,

I am not interested in piping or killing, as I wanna stop transfer exactly after 1%. I hope curl should be useful. Will have a look into that.

/Tamil

Yes, curl has a -r option that is useful if you know the file size before starting the download.

Also, is it possible the 1% is arbitrary? Even if you don't know the file size before, for your test you could download say 1 MB or whatever you choose.

Rather than parse the output of wget how about starting another job to watch the file size. Since this is a controlled test you will know when the file size is 1% and then you can kill the wget pid.

Please correct the subject of the post. It should read pseudo not sudo.

Assuming you know what 1% of the target file is, why would you bother monitoring a file when you can just restrict it through a pipe with dd? Or use curl to request a byte range? Monitoring seems pointlessly inefficient.

Regards,
Aliser

Thanks for the responses !!!

1% is an arbitrary value. How does pipe work? I assume wget gets complete file and passes it to the pipe, which I am not interested in.

I tried curl and its useful. But 1% is changing and hence I don't have fixed byte range for all downloads

That is not correct, as I explained in previous post on this thread. You can confirm this with wget by looking at the wget log file, for example if you run wget -o logfile ... | head and you will see that wget stops working when the pipe breaks.

If 1% is an arbitrary value, then just use something like wget ... | head -c 1MB or wget ... | head -c 1000000

If portability is a concern, be aware that some implementations of head do not offer -c.

You can calculate the 1% byte range from the content-length header of an HTTP HEAD request. Refer to curl's -I (aka --head) option.

Regards,
Alister

Hansan44 and Alister,

Thanks a lot for your responses. :slight_smile:

/Tamil