wget收到文件并挂起

我试图打败奇怪的问题 – 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] 

然后它只是挂起。 此行为不会在其他主机上重现。 请指教。

wget不挂。 您的shell正在等待您input另一个命令,并且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继续运行,将命令行的其余部分解释为variables赋值,然后立即返回。 为了好玩,检查echo $fields的输出:)

要解决该问题,请使用单引号或双引号引用该url。