Http

wget 接收文件並掛起

  • May 6, 2015

我試圖解決奇怪的問題 - 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 正在等待您輸入另一個命令,並且 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 用單引號或雙引號引起來。

引用自:https://serverfault.com/questions/689919