Reputation: 599
I am having a problem with my bash script. It is producing an error of
curl (6) couldn't resolve host
What have I done wrong?
The following is my bash script.
#!/bin/bash
string="$(mysql -u root -p Company 'select name from HR')"
url="http://www.company.com/company/hr/$string"
curl -F $url
Upvotes: 12
Views: 129309
Reputation: 4230
This happened to me when I was mixing single and double quotes in the values of my --header
parameters. Use either all single or all double quotes
Upvotes: 0
Reputation: 2337
This could be a DHCP problem. I was seeing the same and similar error messages trying to update and install NPM packages and run Curl commands in my Window WSL2 Ubuntu terminal. After updating the DNS by running sudo echo nameserver 8.8.8.8 > /etc/resolv.conf
I was able to install and update packages again. I spent days trying to troubleshoot this and never thought to check for DNS issues.
Upvotes: 0
Reputation: 6379
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.
So currently I have no idea of how to distinguish problems on the remote server from problems on our own network.
Upvotes: 0
Reputation: 39
Try printing out the whole string/url. I believe it should have some problems in it.
Upvotes: 3
Reputation: 5064
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.
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]
Upvotes: 5
Reputation: 881573
And can you ping "www.company.com" (I'm assuming that's not the real name you're connecting to) at all?
And it might be worthwhile printing out the $url
variable before you curl
it since it may be malformed.
And one final thing. Are you sure you should be using -F
? This appears to be automated form filling. Is it possible you wanted to "fail silently" option -f
?
Upvotes: 2