LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-07-2012, 10:22 PM   #1
hoa
LQ Newbie
 
Registered: Jun 2012
Posts: 1

Rep: Reputation: Disabled
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
 
Old 06-08-2012, 01:39 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Run shell script on multiple linux servers vanish78 Linux - Newbie 5 05-16-2012 11:42 AM
[SOLVED] ssh into multiple servers and tail -f greenpool Linux - Newbie 7 09-29-2011 12:05 AM
LXer: ssh on multiple servers Using cluster ssh LXer Syndicated Linux News 0 01-11-2008 04:40 PM
SSH to multiple servers DigiCrime Linux - General 6 06-22-2006 09:19 AM


All times are GMT -5. The time now is 08:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration