Unix scripting, trying to hosts, getting “013 not found: 3(NXDOMAIN)”

shellunix

I have a text file, a.txt. Contents are:

$ cat a.txt
microsoft.com
google.com
ibm.com

I'm trying to run a host command on each line to get the IP address. Here is my script:

#!/bin/sh
for i in `cat a.txt`
do
echo $i
host $i
done

When i run it I get this:

$ ./a.sh
microsoft.com
Host microsoft.com\013 not found: 3(NXDOMAIN)
google.com
Host google.com\013 not found: 3(NXDOMAIN)
ibm.com
Host ibm.com\013 not found: 3(NXDOMAIN)

However if in edit my script to explicitly specify the host :

#!/bin/sh
host microsoft.com
host google.com
host ibm.com

It works.

Do you know I get "013 not found: 3(NXDOMAIN)" ?

Thanks
Chris

Best Answer

\013 indicates that you have a carriage return at the end of your host name. Strip it (e.g. using something like tr -d '\r') before passing the host name to 'host'.

Try changing:

for i in `cat a.txt`

to:

for i in `cat a.txt | tr -d '\r'`
Related Topic