bashsshsshpass

Cannot execute the sshpass command after the the first sshpass is excuted


I am trying ssh to each host to run some command, after it is done. The second and the third sshpass command needs to be ran. However, it only run the first command, and then it stops at the second and the third sshpass command. Here is my sample script. I call it is sshHostName.sh script, and the script contains

/usr/bin/sshpass -p 'myPassword' ssh root@hostName1 "echo 'hello1'"
/usr/bin/sshpass -p 'myPassword' ssh root@hostName2 "echo 'hello2'"
/usr/bin/sshpass -p 'myPassword' ssh root@hostName3 "echo 'hello3'"

For this example, I only see hello1 after I run ./sshHostName.sh

How to run the next (sshpass) command once the previous one completed?

Thanks.


Solution

  • I figured out that I need to put this option there: -o StrictHostKeyChecking=no

    /usr/bin/sshpass -p 'myPassword' ssh -o StrictHostKeyChecking=noroot@hostName1 "echo 'hello1'"
    /usr/bin/sshpass -p 'myPassword' ssh -o StrictHostKeyChecking=noroot@hostName2 "echo 'hello2'"
    /usr/bin/sshpass -p 'myPassword' ssh -o StrictHostKeyChecking=noroot@hostName3 "echo 'hello3'"
    

    So it is working!