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 google.com 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?


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.


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,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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