在多台机器上运行相同的脚本 [英] running same script over many machines
问题描述
我已经建立了几个EC2实例,而这一切都在主目录的脚本。我想在每一个EC2实例同时运行该脚本,即没有经历一个循环。
I have setup a few EC2 instances, which all have a script in the home directory. I would like to run the script simultaneously across each EC2 instance, i.e. without going through a loop.
我看到csshX的OSX的终端互动使用率......但不知道命令行code是要执行的命令,像
I have seen csshX for OSX for terminal interactive useage...but was wondering what the commandline code is to execute commands like
ssh user@ip.address . test.sh
要自...
csshX user@ip.address.1 user@ip.address.2 user@ip.address.3 . test.sh
不工作...
does not work...
我想这样做在命令行,因为我想将它添加到一个shell脚本来自动完成这个过程。
I would like to do this over the commandline as I would like to automate this process by adding it into a shell script.
和奖励积分...如果有一种方法将消息发送回设备发送命令,它已经完成运行,将是非常美妙的脚本。
and for bonus points...if there is a way to send a message back to the machine sending the command that it has completed running the script that would be fantastic.
推荐答案
将它足够好,有运行所有这些东西在后台主shell脚本?例如,
will it be good enough to have a master shell script that runs all these things in the background? e.g.,
#!/bin/sh
pidlist="ignorethis"
for ip in ip1 ip2
do
ssh user@$ip . test.sh &
pidlist="$pidlist $!" # get the process number of the last forked process
done
# Now all processes are running on the remote machines, and we want to know
# when they are done.
# (EDIT) It's probably better to use the 'wait' shell built-in; that's
# precisely what it seems to be for.
while true
do
sleep 1
alldead=true
for pid in $pidlist
do
if kill -0 $pid > /dev/null 2>&1
then
alldead=false
echo some processes alive
break
fi
done
if $alldead
then
break
fi
done
回声全部完成。
echo all done.
它不会被精确地同时,但它应该开球远程脚本并联
it will not be exactly simultaneous, but it should kick off the remote scripts in parallel.
这篇关于在多台机器上运行相同的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!