How can I run an application on a remote machine via ssh?
I tried using JSCH, this way:
Properties props = new Properties();
props.put("StrictHostKeyChecking", "no");
String host = "111.111.11.111";
String user = "myuser";
String pwd = "mypass";
// int port = 22;
JSch jsch = new JSch();
Session session = jsch.getSession(user, host);
session.setConfig(props);
session.setPassword(pwd);
session.connect();
System.out.println(session.getServerVersion());
System.out.println("Conected!");
// String command = "ps -ef;date;hostname";
String command = "myapplication someFileAsParameter";
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);
// channel.setInputStream(System.in);
channel.setInputStream(null);
((ChannelExec) channel).setErrStream(System.err);
InputStream in = channel.getInputStream();
channel.connect();
and I have this:
bash: myapplication: command not found
When try execute this command by shell, works fine.
Not necessarily needs to be JSCH, can be anything.