Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

shell

ssh

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?

like image 971
Alex Brown Avatar asked Dec 10 '22 23:12

Alex Brown


1 Answers

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
like image 75
chepner Avatar answered Dec 21 '22 17:12

chepner