LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   shell script ssh to multiple servers (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-ssh-to-multiple-servers-949122/)

hoa 06-07-2012 09:22 PM

shell script ssh to multiple servers
 
Hey all, I'm new to shell scripting and kinda struck here with some of the commands

Code:

#!/usr/bin/expect

spawn ssh dmin@host
expect "password"
send "mypassword\n"
send "command1\n"
send "command2\n"
Interact

I write this simple code for 1 remote host and its working fine

Code:

#!/usr/bin/expect

for host in $(cat SERVERS);
do
spawn ssh dmin@host
expect "password"
send "mypassword\n"
send "command1\n"
send "command2\n"
Interact
EOF
done

However I want to execute the same command to over 20 hosts. Im having some trouble with the it. Is there any recommendation? If I want to use cat function and for loop is this possible and if yes how should I write it? I receive error: "cant' read "(cat hosts)"; no such variable

**btw Im using cygwin terminal to execute the script

evo2 06-08-2012 12:39 AM

Hi,

there are already a number of tools for sshing to and running the same command on multiple hosts. Have a look, for example at, clusterssh, mussh, pssh, taktuk etc.

Also, you should probably be using rsa public/private key authentication instead of entering a password for each host (searching for ssh-keygen and ssh-copy-id should provide a huge number of howtos on this topic).

Cheers,

Evo2.


All times are GMT -5. The time now is 09:23 PM.