3

I'm trying to optimize some experiments with a Java application. The same application is on many machines. I want to run all of them via a bash script with ssh.

I have a bash script that has a while loop to run the application. Like this

while [ $COUNTER -lt $WORKERS ]
do
  ssh  ubuntu@host "java java-app.jar" > /data/some-logs.log 
  ((COUNTER++))
  ((IP_BEGINS++))
done

However when I run the script I have to wait a moment and press Ctrl+C for every machine. How can I run every aplication on background?

3

1 Answer 1

3

prefix with nohup and append a & to the command, that will run it in the background.

while [ $COUNTER -lt $WORKERS ]
do
  ssh  ubuntu@host "nohup java -jar java-app.jar > /data/some-logs.log 2>&1 &"
  ((COUNTER++))
  ((IP_BEGINS++))
done

You might need to muck around with the quotes and placements of the & to make sure the remote ssh command gets backgrounded and not your local ssh

EDIT - I fixed the answer based on your comment. Also added the stderr redirect to the same log file, that might help when things go wrong

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! It worked. However I had to change the prefix and & as you mentioned. ssh ubuntu@host "nohup java java-app.jar > /data/some-logs.log &"

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.