nc command in script vs. in shell
I am using the following Linux command and have tried it in a script (tried it in bash and csh) and from the bash shell:
nc -z -w 2 <hostid> 22 where host ID has been validated as a valid domain (tried it on my own domain name). When I do it at the shell prompt, it works perfectly, but when the script issues the identical command, I get this error: nc: getaddrinfo: Name or service not known Can someone give me an idea as to what I am doing wrong? |
What shell are you using, what hashbang are you using (the #! line at the start of the script), and what command are you using to run the script?
|
nc in script
As stated in my post, I have tried it with both bash (#!/bin/bash) and csh(#!/bin/csh) and my shell is a bash shell.
Also, further investigation shows that the cause is related to the value of the domain name. The domain name comes from this line in my script: for id in (grep -v '^#' ~/hostnames) when I do: echo $id it looks OK, but it clearly is not working. |
I guess you could try full path to nc.
/bin/nc or wherever. I don't know how domain would fail if it works in shell. A script should run nc. |
Problem solved: the grep operation was appending an extra character(0x00) at the end of my domain string. Using substring to remove it removed the cause of the error.
|
Thanks for the update.
|
Well done for posting the solution - could you mark the thread as 'SOLVED' please?
Thanks, |
All times are GMT -5. The time now is 10:39 AM. |