sudo로 실행할 때 wget에서 오류가 발생하는 이유는 무엇입니까? 결과가 나옵니다. Spider mode

나는 다음 명령을 시도했다 :

$ wget -q --tries=10 --timeout=20 --spider http://google.com

( 이 SO 게시물에서 . bash에서 인터넷 연결을 확인하고 싶습니다.)

다음과 같은 결과가 나옵니다.

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.

괜찮아 보이지만으로 cmd를 실행하면 다음과 sudo같은 메시지가 나타납니다.

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

스크립트 에이 줄이 필요합니다.이 스크립트는 sudo항상 호출 하므로 실패합니다.

누군가 나에게 이유를 말해 줄 수 있습니까? 그 문제를 어떻게 해결할 수 있습니까?



답변

환경에 프록시가 정의되어 있습니다. 귀하의 것으로 보입니다 127.0.0.1:3128.

를 실행 sudo하면 프록시 환경 변수가 전달되지 않으므로 직접 확인할 수 없습니다 google.com.

이 명령으로 환경 변수에 정의한 프록시 / 프록시를 확인할 수 있습니다.

env | grep proxy

Ask Ubuntu에 대한 추가 정보

참고 : 당신이 원하는 경우 sudoHTTP 프록시 환경 변수를 전달하는 데,이 시도 :

sudo http_proxy="$http_proxy" wget -q --tries=10 --timeout=20 --spider http://google.com

다음을 사용하여 모든 환경 변수를 전달할 수도 있습니다 sudo -E.

sudo -E wget -q --tries=10 --timeout=20 --spider http://google.com

스택 오버플로에는 sudoing 시 환경 변수를 유지하기위한 다른 옵션 이 있습니다.


답변