I have a program that needs to execute commands on several servers. I did some local tests with Runtime.getRuntime().exec(); and it worked just fine.
But once I want to execute remote commands it doesn't work. For example if I do
ssh [email protected] 'touch /tmp/hello.txt'
it works in my terminal. But it doesn't work in my Java program with:
Runtime.getRuntime().exec("ssh [email protected] 'touch /tmp/hello.txt'");
Do you have a solution to execute remote commands in a simple main.java for test purposes (no need for logs and production security and all) ?
Thank you!
Edit: The goal is to execute a JAR with parameters like this (logs don't really matter but would be nicer):
ssh [email protected] 'java -jar -Dbroker-ip=10.20.30.41 -Dtopic=topic -Dpartition-number=32 -Dthread=8 -Dsource=/tmp/hour_moves /opt/Produce.jar > /tmp/logThread1 &'
Runtime.getRuntime().exec("myscript.sh'");? exec() is wierd on Java. I always go back to this article: javaworld.com/article/2071275/core-java/…