Skip to content
Advertisement

“Name or service not knownname” using SSH from script [closed]

Cannot connect to host by SSH.

I am using following shell script to use ssh.

host_list="c15-0330-14.ad.mtu.edu"
ssh "$host_list"

But It always says : Name or service not knownname c15-0330-14.ad.mtu.edu.

I tried ssh c15-0330-14.ad.mtu.edu. It works. Also, If I have several hosts, how can I invoke them one by one?

Advertisement

Answer

The error message should be

ssh: Could not resolve hostname c15-0330-14.ad.mtu.edu: Name or service not known

except the DOS line endings in your script cause an extra carriage return to be stored at the end of the value of host_list. This carriage return, when printed as part of the error message, causes the cursor to return to the beginning of the line, resulting in the error message you actually see. Notice how the two halves line up (the carriage return immediately precedes the colon):

ssh: Could not resolve hostname c15-0330-14.ad.mtu.edu
: Name or service not known

results in your error of

: Name or service not knownname c15-0330-14.ad.mtu.edu
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement