1

My script is:

for i in $(seq $nb_lignes) a list of machines
do
ssh root@$machine -x "java ....." 
sleep 10
done

--> i execute this script from machine C

i have two machines A and 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)

i run the script from machine C: i'd like that it display : node 1 is created , wait 10 seconds and display node 2 is created

My problem: it display node 1 is created only

i tape ctrl+c it diplay node 2 is created

PS: the two process java are still runing in machine A and B

Thank you

1
  • 2
    Your loop is for i in ..., but you refer to $machine in the body of the loop. I guess what you really meant was for machine in .... Please post code that's as close as possible to the code you're actually running, so we don't have to guess which problem are in your original code and which you introduced when you re-typed it. Commented Oct 11, 2012 at 0:04

2 Answers 2

2

From the way I'm reading this, armani is correct; since your java program does not exit, the second iteration of the loop doesn't get run until you "break" the first one. I would guess that the Java program is ignoring a break signal sent to it by ssh.

Rather than backgrounding each SSH with a &, you're probably better off using the tools provided to you by ssh itself. From the ssh man page:

 -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.

So ... your script would look something like this:

for host in machineA machineB; do
    ssh -x -f root@${host} "java ....." 
    sleep 10
done
Sign up to request clarification or add additional context in comments.

Comments

1

Try the "&" character after the "ssh" command. That spawns the process separately [background] and continues on with the script.

Otherwise, your script is stuck running ssh.

EDIT: For clarity, this would be your script:

for i in $(seq $nb_lignes) a list of machines
do
ssh root@$machine -x "java ....." &
sleep 10
done

4 Comments

Further explanation: Being stuck in the first SSH program, when you Ctrl-C you kill THAT process, and THEN you are allowed to move on to creating node 2. See why it would say that after you hit Ctrl-C?
no with ctrl-C the process is not killed, when i tappe ctrl+C it passes au second iteration (the shell does not return with ctrl+c .. it passes au second iteration and it display node 2 is created!!
:i can't access now to the machines, i have already add & but it did'nt execute sleep 10!
Please, i have another question, how can display only the result of command java of node A only , i'd like redirect that of B ? thank you so much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.