I tried the following command:
$ wget -q --tries=10 --timeout=20 --spider http://google.com
(From this SO post. I want to check my internet connection in bash.)
I get following output:
Spider mode enabled. Check if remote file exists.
--2015-09-28 09:55:50-- http://google.com/
Connecting to 127.0.0.1:3128... connected.
Proxy request sent, awaiting response... 302 Found
Location: http://www.google.de/?gfe_rd=cr&ei=k_IIVreaN-yH8Qfe1Yu4CA [following]
Spider mode enabled. Check if remote file exists.
--2015-09-28 09:55:50-- http://www.google.de/?gfe_rd=cr&ei=k_IIVreaN-yH8Qfe1Yu4CA
Connecting to 127.0.0.1:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Remote file exists and could contain further links,
but recursion is disabled -- not retrieving.
Seems OK, however running the cmd with sudo
, I receive this:
Spider mode enabled. Check if remote file exists.
--2015-09-28 09:55:27-- http://google.com/
Resolving google.com (google.com)... failed: Name or service not known.
wget: unable to resolve host address ‘google.com’
I need this line in a script, which I call with sudo
and so it always fails.
Can somebody tell me the reason for this? How can I work around that?
You have a proxy defined in your environment. Yours appears to be 127.0.0.1:3128
.
When you run sudo
, the proxy environment variable isn't passed, which is why you can't directly resolve google.com
.
You can see what proxy/proxies you have defined in your environment variables with this command:
env | grep proxy
Additional information on Ask Ubuntu
Note: If you want sudo
to pass the HTTP proxy environment variable, try this:
sudo http_proxy="$http_proxy" wget -q --tries=10 --timeout=20 --spider http://google.com
You can also pass all environment variables using sudo -E
:
sudo -E wget -q --tries=10 --timeout=20 --spider http://google.com
Stack Overflow has other options for keeping the environment variable when sudo
ing.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다