How to set wget to timeout after downloading more than a fixed duration

5

1

I want wget to (attempt to) start downloading, then if isn't done after 10 seconds, I want it to give up.

wget --timeout 10 http://url

Seems like a reasonable try, but it seems like it only sets --dns-timeout, --connect-timeout, and --read-timeout. Thus, it could wait 9 seconds for dns, another 9 for connect and then keep downloading forever, as long as data keeps coming at a steady pace (no 10+ second pause).

johv

Posted 2012-01-20T22:39:13.467

Reputation: 151

Answers

1

Basically this will be something like:

wget http://www.somesite.com/file.zip &
PID=$!
sleep 10
if [ `ps ax | grep $PID` -ne '' ]
   then
   kill $PID
fi

ccpizza

Posted 2012-01-20T22:39:13.467

Reputation: 5 372

That's one way to solve it, ugly as it is. – johv – 2012-02-25T12:55:22.253

0

This isn't exactly what you're asking as this should only cause Wget to timeout if the download idles for more than 10 seconds:

wget --read-timeout= 10 http://url

About the --read-timeout option, from the Wget 1.13.4 Manual:

Set the read (and write) timeout to seconds seconds. The “time” of this timeout refers to idle time: if, at any point in the download, no data is received for more than the specified number of seconds, reading fails and the download is restarted. This option does not directly affect the duration of the entire download.

Kenny Evitt

Posted 2012-01-20T22:39:13.467

Reputation: 273