Bash - Curl (6) 无法解决主机问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8922061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash - Curl (6) couldn't resolve host issue
提问by Hend
I am having a problem with my bash script. It is producing an error of
我的 bash 脚本有问题。它产生了一个错误
curl (6) couldn't resolve host
curl (6) couldn't resolve host
What have I done wrong?
我做错了什么?
The following is my bash script.
以下是我的 bash 脚本。
#!/bin/bash
string="$(mysql -u root -p Company 'select name from HR')"
url="http://www.company.com/company/hr/$string"
curl -F $url
采纳答案by J eremy
Try printing out the whole string/url. I believe it should have some problems in it.
尝试打印出整个字符串/url。我相信它应该有一些问题。
回答by Jasonw
According to the man curl, error 6 means "Couldn't resolve host. The given remote host was not resolved." so you will have to check if the hostname of the url is resolvable to an ip address.
根据 man curl 的说法,错误 6 表示“无法解析主机。未解析给定的远程主机。” 所以你必须检查 url 的主机名是否可以解析为 IP 地址。
when you need to submit data to a server, for example with the form below,
当您需要向服务器提交数据时,例如使用下面的表格,
<form method="POST" enctype='multipart/form-data' action="upload.cgi">
<input type=file name=upload>
<input type=submit name=press value="OK">
</form>
you can do it curl with the following equivalent. (make sure the server that you submitted is ready to receive the data too)
您可以使用以下等效项来卷曲。(确保您提交的服务器也已准备好接收数据)
curl -F upload=@localfilename -F press=OK [resolv-able url]
回答by paxdiablo
And can you ping"www.company.com" (I'm assuming that's not the realname you're connecting to) at all?
你能不能ping“www.company.com”(我假设这不是你连接的真实姓名)?
And it might be worthwhile printing out the $url
variable before you curl
it since it may be malformed.
并且$url
在您之前打印出变量可能是值得的curl
,因为它可能格式不正确。
And one final thing. Are you sureyou should be using -F
? This appears to be automated form filling. Is it possible you wanted to "fail silently" option -f
?
还有最后一件事。你确定你应该使用-F
?这似乎是自动填写表格。您是否可能想“静默失败”选项-f
?
回答by Aerendir
Just for completeness: this happens also if there are problems on your network.
只是为了完整性:如果您的网络出现问题,也会发生这种情况。
For instance, to test this, on your local machine shutdown the connection to the internet and try to connect to the URL: the exact same error is returned.
例如,要对此进行测试,请在您的本地计算机上关闭与 Internet 的连接并尝试连接到 URL:返回完全相同的错误。
So currently I have no idea of how to distinguish problems on the remote server from problems on our own network.
所以目前我不知道如何区分远程服务器上的问题和我们自己网络上的问题。