j2ssh to run multiple commands
Hi ,
i am new here , so if i have mistake , i am sorry :)
i wrote a little program to run commands on a remote unit , i used the j2ssh .
it all works well for 1 commmand , and the output is just as expected.
when running the program with more than 2 commands , i dont get the output String .
working Command :
cd /usr/cti/bin;ls -la;
no 'ls -la' output :
cd /usr/cti/bin;pwd;ls -la;
Code:
if ( CreateSSHconnection(_UnitIP) )
{
try {
SessionChannelClient session = ssh.openSessionChannel();
InputStream in = session.getInputStream(); // start input stream for ssh result
BufferedReader br = new BufferedReader(new InputStreamReader(in)); // read to buffer from the stream
StringBuffer buffer = new StringBuffer();
logger.debug("Starting to execute commands on Unit : " + _UnitIP);
session.executeCommand(_command); // execute the command via SSH session
while (((line = br.readLine()) != null)) // read from the buffer of the stream the line
buffer.append(line + " \n "); // append the result line to the String buffer.
output = buffer.toString(); // Convert the output line from stringbuffer to String.
session.close(); // close the SSH session.
ssh.disconnect();
return output;
}
catch(Exception exGeneral){
logger.error("failed to execute the command : " + exGeneral.getMessage());
return null;
}
}
else{
logger.error("SSH connection was not created ! ");
return null;
}
any help will be great :) , thanks !