Reputation: 534
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?
Upvotes: 3
Views: 70
Reputation: 7067
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
Upvotes: 3