views:

55

answers:

3

I have a script that connects to a server using ssh. While in a loop, it fails to connect to the second server after connecting to the first one. I guess I have to quit from that server to come back to the calling script. How do I quit the ssh session?

while read dbname myip
do
ssh root@$myip "mysqldump - some command " | mysql -hhost -u -p myLocalDatabase > /dev/null 2>&1
done << iplist
db1 111.111.111.111
xyz 222.222.222.222
iplist
A: 

If you want to issue the same command on multiple SSH hosts, you can use DSH:

dsh is an implementation of a wrapper for executing multiple remote shell (rsh/remsh/ssh) commands.

+1  A: 

At a slightly higher level of abstraction, you may be interested in e.g. Chef:

Chef is a systems integration framework, built to bring the benefits of configuration management to your entire infrastructure. With Chef, you can:

  • Manage your servers by writing code, not by running commands. (via Cookbooks)
  • Integrate tightly with your applications, databases, LDAP directories, and more. (via Libraries)
  • Easily configure applications that require knowledge about your entire infrastructure ("What systems are running my application?" "What is the current master database server?")
Conrad Meyer
+1  A: 

redirect stdin to /dev/null

while  read -r dbname myip
do
 0</dev/null ssh ...... <whatever> .........
done < "iplist"
This is exactly what I wanted. Thanks.
shantanuo