9月 09

wgetの再試行オプション

楽しみにしていたRaspbianのダウンロードが止まってました.
停電やルーター不調とかで回線イマイチなのです.

なのでwgetcとか適当なscriptを用意して

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/sh

if [ $# -eq 0 ]; then
  echo "$0 URL" 1>&2
  exit 1
fi

while :
do

wget -c $1

if [ "$?" -eq 0 ]; then
  echo "Done!" 1>&2
  exit 0;
fi

sleep 1

done

chmod +x してこんな感じでダウンロード

$ wgetc http://vx2-downloads.raspberrypi.org/raspbian/images/raspbian-2017-09-08/2017-09-07-raspbian-stretch.zip ; wgetc http://vx2-downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2017-09-08/2017-09-07-raspbian-stretch-lite.zip ; sha256sum raspbian*.zip

3回ほどの試行でどうにか終わってました.

そして返り値ちゃんと確認するかとwgetのmanを見たら…….

       --retry-connrefused
           Consider "connection refused" a transient error and try again.  Normally Wget gives up on a URL when it is unable to connect to the site
           because failure to connect is taken as a sign that the server is not running at all and that retries would not help.  This option is for
           mirroring unreliable sites whose servers tend to disappear for short periods of time.
       --waitretry=seconds
           If you don't want Wget to wait between every retrieval, but only between retries of failed downloads, you can use this option.  Wget will use
           linear backoff, waiting 1 second after the first failure on a given file, then waiting 2 seconds after the second failure on that file, up to
           the maximum number of seconds you specify.

           By default, Wget will assume a value of 10 seconds.

実装されてましたorz

$ wget -c --retry-connrefused [URL]

な感じで良さそう.
次の機会に試してみます.