English 中文(简体)
ssh issue in a loop
原标题:
  • 时间:2009-11-26 07:17:02
  •  标签:
  • shell
  • ssh

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
最佳回答

redirect stdin to /dev/null

while  read -r dbname myip
do
 0</dev/null ssh ...... <whatever> .........
done < "iplist"
问题回答

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?")

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.

If you don t have whitespace in the lines of file "dbname", you can use this:

for myip in $(cat dbname); do
   ...
done

(or use fabric: http://docs.fabfile.org/en/latest/)





相关问题
KornShell- Creating a fixed width text file

I need to create a simple fixed width text file in KornShell (ksh). My current attempt using printf to pad the string isn t working out very well. What s the shortest, cleanest way to create a fixed ...

unix find command

how to use the find command to find files/directories which are not matching the pattern. for eg: find <some options > -name "dontfile.txt" should give me output of all the find whose file ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

1. 露台式照像

在Windows XP中,没有一时出现指挥时,是否有办法操作一种灰色文字? 我常常需要把“善待”(工作)与“灰色”同起来,即使我的文字没有产出,......

热门标签