Execute Unix commands using Jsch maven
I'm trying use this code for performing the following steps, but it's not working!.
- String command1 = "ls -ltr"
- String command2 = "cd /test/user/"
- String command3 = "./test.sh"
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
JSch jsch = new JSch();
Session session=jsch.getSession(user, host, 22);
session.setPassword(password);
session.setConfig(config);
session.connect();
System.out.println("Connected");
Channel channel=session.openChannel("exec");
((ChannelExec)channel).setCommand(command1);
// From above command does work! It lists the files.
((ChannelExec)channel).setCommand(command2);
Above commandBut the last line doesn't work! Nothing happens-- stuck here! Could anyone help out with this problem?nothing happens.