Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash - Curl (6) couldn't resolve host issue

Tags:

bash

curl

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
like image 718
Hend Avatar asked Jan 19 '12 06:01

Hend


People also ask

Could not resolve host error 6?

cURL error 6. The error indicates that the network that UpdraftPlus is attempting to connect to is unreachable. This shows that the connection isn't being blocked, but is failing to reach the UpdraftPlus.com servers.

Why cURL Could not resolve host?

The reason curl fails is simply because the DNS resolution is missing.

How do I fix unable to resolve host?

Since the hostname is missing and your system is not able to figure out the hostname and thus it throws the error 'sudo: unable to resolve host'. To fix this error, edit the /etc/hosts file and set the hostname (newpc) with a loopback address (127.0. 0.1).


3 Answers

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]
like image 72
Jasonw Avatar answered Sep 23 '22 07:09

Jasonw


Try printing out the whole string/url. I believe it should have some problems in it.

like image 26
J eremy Avatar answered Sep 21 '22 07:09

J eremy


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?

like image 41
paxdiablo Avatar answered Sep 23 '22 07:09

paxdiablo