在退出之前,您期望此命令需要多长时间?
wget --timeout=1 --tries=2 "http://www.google.com:81/not-there"
我希望超时1秒,2次尝试意味着2秒,但需要6.025秒
wget --timeout=1 --tries=2 "http://www.google.com:81/not-there"
--2017-04-27 16:49:12--http://www.google.com:81/not-there
Resolving www.google.com (www.google.com)... 209.85.203.105, 209.85.203.103, 209.85.203.99, ...
Connecting to www.google.com (www.google.com)|209.85.203.105|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.103|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.99|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.104|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.106|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.147|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|2a00:1450:4009:80d::2004|:81... failed: Network is unreachable.
我不知道为什么它会在戒烟前尝试6次。
似乎tries
用于重试。如果我设置--retry-connrefused
它至少会重试,但仍然花费的总时间不是我所期望的。我希望能够决定应该尝试超时的次数。
修改:
在@Socowi提出建议之后,我尝试将waitretry与retry-connrefused结合使用并获得相同的行为:
$ wget --timeout=1 --waitretry=0 --tries=2 --retry-connrefused "http://www.google.com:81/not-there"
--2017-04-27 20:29:47-- http://www.google.com:81/not-there
Resolving www.google.com (www.google.com)... 2a00:1450:400b:c00::68, 209.85.203.99, 209.85.203.147, ...
Connecting to www.google.com (www.google.com)|2a00:1450:400b:c00::68|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.99|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.147|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.103|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.104|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.106|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.105|:81... failed: Connection timed out.
Retrying.
--2017-04-27 20:29:54-- (try: 2) http://www.google.com:81/not-there
Connecting to www.google.com (www.google.com)|2a00:1450:400b:c00::68|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.99|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.147|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.103|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.104|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.106|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.105|:81... failed: Connection timed out.
Giving up.
编辑两个
当两个相同的命令表现不同时,我真的很困惑。
root@8c59d6dd05fe:/var/www/html# wget --timeout=1 --waitretry=0 --tries=2 --retry-connrefused "http://www.google.com:81/not-there"
converted 'http://www.google.com:81/not-there' (ANSI_X3.4-1968) -> 'http://www.google.com:81/not-there' (UTF-8)
--2017-04-27 19:50:28-- http://www.google.com:81/not-there
Resolving www.google.com (www.google.com)... 216.58.211.164, 2a00:1450:4009:805::2004
Connecting to www.google.com (www.google.com)|216.58.211.164|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|2a00:1450:4009:805::2004|:81... failed: Cannot assign requested address.
Retrying.
--2017-04-27 19:50:29-- (try: 2) http://www.google.com:81/not-there
Connecting to www.google.com (www.google.com)|216.58.211.164|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|2a00:1450:4009:805::2004|:81... failed: Cannot assign requested address.
Giving up.
root@8c59d6dd05fe:/var/www/html# wget --timeout=1 --waitretry=0 --tries=2 --retry-connrefused "http://www.google.com:81/not-there"
converted 'http://www.google.com:81/not-there' (ANSI_X3.4-1968) -> 'http://www.google.com:81/not-there' (UTF-8)
--2017-04-27 19:50:35-- http://www.google.com:81/not-there
Resolving www.google.com (www.google.com)... 209.85.203.104, 209.85.203.147, 209.85.203.106, ...
Connecting to www.google.com (www.google.com)|209.85.203.104|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.147|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.106|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.103|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.105|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.99|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|2a00:1450:400b:c03::68|:81... failed: Cannot assign requested address.
Retrying.
--2017-04-27 19:50:41-- (try: 2) http://www.google.com:81/not-there
Connecting to www.google.com (www.google.com)|209.85.203.104|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.147|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.106|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.103|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.105|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|209.85.203.99|:81... failed: Connection timed out.
Connecting to www.google.com (www.google.com)|2a00:1450:400b:c03::68|:81... failed: Cannot assign requested address.
Giving up.
我以为我有点疯狂,但只有当@Socowi在评论中指出,每次重试的IP都是点击的。它取决于返回的可能IP的数量。我看到的神奇数字7(重试)是IP选项的编号。当我只选择一个特定的IP时,它只尝试一次。
答案 0 :(得分:8)
您的wget似乎将URL解析为多个IP地址,如wget
输出的第二行所示。然后使用指定的超时测试每个IP。不幸的是,我没有找到任何选项来限制DNS查找到一个地址或设置所有IP的总超时。但您可以尝试使用"<googles ip address>:81/not-there"
代替网址。
正如您已经发现的那样,即使在连接被拒绝«错误后,设置--retry-connrefused
也可以wget
重试。指定的超时用于每次重试,但在重试之间会有一个暂停,每次重试后都会更长。
wget --timeout=1 --tries=5 --retry-connrefused URL
做类似
的事情try to connect for 1 second
failed -> wait 1 second
try to connect for 1 second
failed -> wait 2 seconds
try to connect for 1 second
failed -> wait 3 second
try to connect for 1 second
failed -> wait 4 second
try to connect for 1 second
因此该命令需要tries * timeout + 1 + 2 + ... + (tries - 1)
秒。此行为在选项下的man wget
中指定,允许您更改它:)
<强> - waitretry =秒强>
如果您不希望Wget在每次检索之间等待,但仅限于 在重试失败的下载之间,您可以使用此选项。 wget的 将使用线性退避,在第一次失败后等待1秒 在给定文件上,然后在第二次失败后等待2秒 该文件,最多为您指定的最大秒数。默认情况下,Wget将假设值为10秒。
我想你想要使用像
这样的东西wget --timeout=1 --waitretry=0 --tries=5 --retry-connrefused URL
消除了两次重试之间的暂停,导致总时间为timeout * tries
。