Ssh "port 22: no route to host" error in bash script

I wrote a script to execute a couple of remote ssh commands related to the Apache assault. When I execute the script, it says:

ssh: connect to host XXX.XXX.XXX.XXX port 22: No route to host
ssh: connect to host XXX.XXX.XXX.XXX port 22: No route to host
ssh: connect to host XXX.XXX.XXX.XXX port 22: No route to host
ssh: connect to host XXX.XXX.XXX.XXX port 22: Connection refused

      

If I execute the commands manually, it works well and I can ping the machine. So there must be something wrong with this code:

while [ $i -le $numVM ]

do
    if [ $i -eq 1 ];then
        ssh -i file root@IP1 './zookeeper-3.4.6/bin/zkServer.sh start' 
    else
        ssh -i file root@IP2 'sed -i '"'"'s/#\ storm.zookeeper.servers.*/storm.zookeeper.servers:/'"'"' /root/apache-storm-0.9.3/conf/storm.yaml'
        ssh -i file root@IP2 'sed -i '"'"'0,/^#[[:space:]]*-[[:space:]]*\"server1\".*/s//"      - \"'${IParray[1]}'\""/'"'"' /root/apache-storm-0.9.3/conf/storm.yaml'
        ssh -i file root@IP2 'sed -i '"'"'s/#\ nimbus.host:.*/"nimbus.host: \"'${IParray[2]}'\""/'"'"' /root/apache-storm-0.9.3/conf/storm.yaml'
        ssh -i file root@IP2 './zookeeper-3.4.6/bin/zkCli.sh -server ${IParray[1]} &'
        sleep 10
        ssh -i file root@IP2 './apache-storm-0.9.3/bin/storm nimbus &' &
        sleep 10
        ssh -i file root@IP2 './apache-storm-0.9.3/bin/storm ui &' & 
        sleep 10
        ssh -i file root@IP2 './apache-storm-0.9.3/bin/storm supervisor &' &
    fi  
    ((i++))
done

      

I am running multiple processes on two virtual machines that are deployed from the same image, so they are largely identical. The confusing part is that the first ssh command (running zkServer.sh) works well, but if I script tries three sed commands, I get the above error. But then the last four ssh commands work well again. It doesn't make any sense to me ...

+3


source to share


2 answers


Then for the solution posted here, check out this link.



click here to solve the problem

+1


source


Several things I can think of:

  • Most daemons sshd

    do not allow access to root

    . Heck, many Unix / Linux versions no longer allow root login. If you need root access, you need to use sudo

    .
  • The daemon sshd

    on the remote computer is not running. While this is rare, some sites have never been able to configure it or purposefully disable it as a security issue.
  • Invalid commands ssh

    .

Instead of running commands ssh

in your shell script, change your shell script to print out what you are trying to execute. Then see if the command can be executed outside of the shell script. This way you can determine if the problem is a shell script or if the problem is with the command itself ssh

.



If your commands ssh

don't work outside of the command line, you can simplify them and see if you can determine what the problem is. You have ssh -i file root@IP2

. Is it supposed to be that ssh -i $file root@$IP2

? (i.e. you are missing the senior sigil).

$ ssh -i file root@$IP2 ls   # Can't get simpler than this...
$ ssh -i file root@IPS       # See if you can remotely log on...
$ ssh root@IP2               # Try it without an 'identity file'
$ ssh bob@IP2                # Try it as a user other than 'root'
$ telnet IP2 22              # Is port 22 even open on the remote machine?

      

If they don't work, you have a very big problem configuring the command on the remote computer sshd

.

-1


source







All Articles