wget receives the file and hangs

user1065145 asked:

I am trying to beat weird problem – wget gets the file, saves it to disk and hangs. Here is the details:

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

Detailed log:

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]

Then it just hangs. This behaviour doesn’t reproduce on other hosts. Please, advise.

My answer:


wget is not hanging. Your shell is waiting for you to enter another command, and the shell prompt is at the top of the output somewhere…

The problem is: You did not quote the URL, and it contains an ampersand. This character is used to put a process in the background, and importantly, anything following it is treated as another command line to be run.

So the shell treated this as two commands:

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&

and

fields=first_name,last_name,photo,photo_big

Since wget was placed in the background, the shell continued on, interpreted the remainder of the command line as a variable assignment, and then returned immediately. For fun, inspect the output of echo $fields 🙂

To resolve the problem, quote the URL in single or double quotes.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.