Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have script which reads from method file :

OPTIONS

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

#!/bin/bash
#
#
if [ ! $# == 1 ]
then
        echo "Usage: $0 [ URL ]"
        exit 1
fi

cat method | while read LINE
                do
                cat << __eof > header
$LINE / HTTP/1.1
Host:$1


__eof
nc $1 80 < header
done

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?

share|improve this question

2 Answers 2

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:

'127.0.0.1 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,
Jochen

share|improve this answer

Your Answer

 
discard

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.