【问题标题】:Wait functionality in Wget not working as expectedWget 中的等待功能未按预期工作
【发布时间】:2017-08-17 21:00:17
【问题描述】:

背景:
我在 RedHat Linux(版本 7.3 (Maipo))上的 Bash(版本 4.2.46(1))终端中使用 wget(版本 1.14-15.el7)。

不幸的是,我仅限于这个特定的 RHEL 映像,所以我无法升级到更新版本的 wget。

目标:
我正在尝试配置 wget,以便在下载尝试失败时执行以下操作:
1) 重试下载 4 次(共 5 次尝试)
2) 在下载尝试(“重试”)之间等待固定的时间(30 秒)

关于上下文,这里是wget手册的相关sn-p:

   -w seconds
   --wait=seconds
       Wait the specified number of seconds between the retrievals.  Use of this option is
       recommended, as it lightens the server load by making the requests less frequent.
       Instead of in seconds, the time can be specified in minutes using the "m" suffix, in
       hours using "h" suffix, or in days using "d" suffix.

       Specifying a large value for this option is useful if the network or the destination
       host is down, so that Wget can wait long enough to reasonably expect the network error
       to be fixed before the retry.  The waiting interval specified by this function is
       influenced by "--random-wait", which see.

   --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.

需要明确的是,我使用的是--wait 标志,而不是--waitretry 标志。

流程:

首先,我导出/设置了错误的 http_proxy 和 https_proxy,以确保任何下载尝试都会超时。

我运行以下命令: wget --tries=5 --wait=30 <url> -O <output_filename>

此时,--wait 功能无法按预期工作。具体来说,它不会在每次下载尝试后等待 30 秒。

相反:
1)第一次尝试后,等待1s。
2)第二次尝试后,等待2s。
3)第3次尝试后,等待3s。
等等……

换句话说,尽管使用了--wait 标志(这应该导致下载尝试之间的等待时间固定),wget 似乎正在执行“线性退避”,如--waitretry 标志部分所述。

问题:
我想要--wait 标志的功能,而不是--waitretry 标志。

不幸的是,--wait 标志似乎与--waitretry 标志一样 - 有没有办法解决 wget 中这个明显的错误,以便使用--wait 标志导致预期的固定等待时间两次下载尝试之间?

【问题讨论】:

  • 有关通用计算硬件和软件的问题对于 Stack Overflow 来说是题外话,除非它们直接涉及主要用于编程的工具。您可以通过superuser.com/questions/tagged/linux 获得帮助
  • 谢谢,我会把它移到那里。

标签: linux wget rhel


【解决方案1】:

从您提供的--help 对话框中可以看出,我相信您应该能够在命令中使用--waitretry,类似get --tries=5 --waitretry=30 <url> -O <output_filename> 的东西应该可以工作!

【讨论】:

  • 谢谢,但我实际上不想要--waitretry 提供的功能(其中 wget 执行线性退避)。我正在寻找 wget 在下载尝试之间等待固定的时间,这应该由 --wait 标志提供,但由于某种原因,它不起作用。
  • --wait 有点像超时,因此它等待响应 x 秒,而不是作为尝试之间的睡眠。使用--wait=30,它会发送一个请求并等待最多30秒,然后由于超时而失败。
猜你喜欢
  • 2019-04-19
  • 2013-08-29
  • 2020-03-04
  • 2013-12-10
  • 2019-04-07
  • 2020-04-28
  • 2021-08-27
  • 1970-01-01
  • 2022-01-22
相关资源
最近更新 更多