我正在尝试解决一个奇怪的问题 - wget 获取文件,将其保存到磁盘并挂起。以下是详细信息:
wget --server-response --ca-directory=/etc/ssl/certs --no-dns-cache -T 1 --read-timeout=1 --header="Connection: close" https://api.vk.com/method/users.get?uids=1&fields=first_name,last_name,photo,photo_big
详细日志:
Setting --server-response (serverresponse) to 1
Setting --ca-directory (cadirectory) to /etc/ssl/certs
Setting --dns-cache (dnscache) to 0
Setting --timeout (timeout) to 1
Setting --read-timeout (readtimeout) to 1
Setting --header (header) to Connection: close
DEBUG output created by Wget 1.11.4 on linux-gnu.
--2015-05-06 10:44:04-- https://api.vk.com/method/users.get?uids=1
Resolving api.vk.com... 87.240.131.117, 87.240.131.118, 87.240.131.119, ...
Connecting to api.vk.com|87.240.131.117|:443... connected.
Created socket 3.
Releasing 0x0000000001b6d5e0 (new refcount 0).
Deleting unused 0x0000000001b6d5e0.
Initiating SSL handshake.
Handshake successful; connected socket 3 to SSL handle 0x0000000001b6f070
certificate:
subject: /OU=Domain Control Validated/CN=*.vk.com
issuer: /C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certs.godaddy.com/repository//CN=Go Daddy Secure Certificate Authority - G2
X509 certificate successfully verified and matches host api.vk.com
---request begin---
GET /method/users.get?uids=1 HTTP/1.0
User-Agent: Wget/1.11.4
Accept: */*
Host: api.vk.com
Connection: close
---request end---
HTTP request sent, awaiting response...
---response begin---
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 06 May 2015 06:44:04 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 65
Connection: close
X-Powered-By: PHP/3.13576
Set-Cookie: remixlang=3; expires=Tue, 03 May 2016 15:01:31 GMT; path=/; domain=.vk.com
Pragma: no-cache
Cache-control: no-store
---response end---
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 06 May 2015 06:44:04 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 65
Connection: close
X-Powered-By: PHP/3.13576
Set-Cookie: remixlang=3; expires=Tue, 03 May 2016 15:01:31 GMT; path=/; domain=.vk.com
Pragma: no-cache
Cache-control: no-store
cdm: 1 2 3 4 5 6 7 8
Stored cookie vk.com -1 (ANY) / <permanent> <insecure> [expiry 2016-05-03 19:01:31] remixlang 3
Length: 65 [application/json]
Saving to: `users.get?uids=1.13'
100%[=====================================================================================================================================================================>] 65 --.-K/s in 0s
Closed 3/SSL 0x0000000001b6f070
2015-05-06 10:44:04 (7.92 MB/s) - `users.get?uids=1.13' saved [65/65]
然后它就挂了。这种行为不会在其他主机上重现。请提供建议。
答案1
wget 没有挂起。您的 shell 正在等待您输入另一个命令,并且 shell 提示符位于输出顶部的某处...
问题是:您没有引用 URL,并且它包含一个 & 符号。此字符用于将进程置于后台,重要的是,它后面的任何内容都被视为要运行的另一个命令行。
因此 shell 将其视为两个命令:
wget --server-response --ca-directory=/etc/ssl/certs --no-dns-cache -T 1 --read-timeout=1 --header="Connection: close" https://api.vk.com/method/users.get?uids=1&
和
fields=first_name,last_name,photo,photo_big
由于 wget 被置于后台,因此 shell 继续运行,将命令行的其余部分解释为变量赋值,然后立即返回。为了好玩,请检查echo $fields
:)的输出
要解决该问题,请用单引号或双引号引用 URL。