Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have script which reads from method file :


and checks whether the OPTIONS is allowed on a particular site. The script is :

if [ ! $# == 1 ]
        echo "Usage: $0 [ URL ]"
        exit 1

cat method | while read LINE
                cat << __eof > header
$LINE / HTTP/1.1

nc $1 80 < header

So I can run this test against and other sites. But when I run against localhost:8080 I get an error :

nc: getaddrinfo: Name or service not known

I'm very new to scripting. Can anyone help me out?

share|improve this question
up vote 1 down vote accepted

I don't think it is a problem of scripting but your syntax at the nc command.

nc syntax is: nc -l -p port [-options] [hostname] [port] See man nc for further info.

When using the nc command, hostname is followed by port(s) separated by blank(s). If you call your script with parameter localhost:8080 the shell will not translate this so the port will be regarded as part of the hostname.

share|improve this answer

To fix this add the following to your /etc/hosts, if it is not already there which is on most if not all ubuntu releases:

' localhost'

However I agree with Jens. It seems your syntax is incorrect. Yuu say you run it against localhost:8080 however in your script port 80 is hard coded, meaning you actualy say port 80 on host localhost:8080 and of course that host does not exist.

Kind regards,

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.