我的脚本是:
for i in $(seq $nb_lignes) a list of machines
do
ssh root@$machine -x "java ....."
sleep 10
done-->我在C机器上执行这个脚本
我有两台机器A和B ($nb_lignes=2)
ssh root@$machineA -x "java ....." : create a node with Pastry overlay
wait 10 secondes
ssh root@$machineB -x "java .....":create another node join the first (that's way i have use sleep 10 secondes)我从机器C运行脚本:我希望它显示:节点1已创建,等待10秒,然后显示节点2已创建
我的问题:它只创建了显示节点1
I tape ctrl+c it显示节点2已创建
PS:机器A和B中的两个进程java仍在运行
谢谢
发布于 2012-10-11 07:37:41
从我的理解来看,java armani是正确的;因为你的程序不会退出,直到你“中断”了第一次循环,循环的第二次迭代才会运行。我猜测Java程序忽略了ssh发送给它的break信号。
与其使用&作为每个SSH的背景,不如使用ssh本身提供的工具。从ssh手册页:
-f Requests ssh to go to background just before command execution.
This is useful if ssh is going to ask for passwords or
passphrases, but the user wants it in the background. This
implies -n. The recommended way to start X11 programs at a
remote site is with something like ssh -f host xterm.所以..。您的脚本将如下所示:
for host in machineA machineB; do
ssh -x -f root@${host} "java ....."
sleep 10
done发布于 2012-10-11 03:34:16
在"ssh“命令后尝试使用"&”字符。这将在后台单独生成进程,并继续执行脚本。
否则,您的脚本将停滞在运行ssh。
编辑:为了清晰起见,这将是您的脚本:
for i in $(seq $nb_lignes) a list of machines
do
ssh root@$machine -x "java ....." &
sleep 10
donehttps://stackoverflow.com/questions/12826846
复制相似问题