I think you need STDOUT/STDERR in order to know of the command ran or not. I would use the ChannelShell instead of exec and then run your script. If you receive the prompt then you know your command executed and you can terminate your session. Found a decent example here:

http://stackoverflow.com/questions/12754652/ssh-to-unix-run-a-command-and-fetch-results-from-java



On 5/19/2013 4:42 AM, Ravi Joshi wrote:
Hi all,

I want to invoke a shell script on remote Linux machine using JSch without waiting for the STDOUT/STDERR from the shell. I have modified the code available in JSch official website in the following manner-

        String command = "sh /opt/scripts/start.sh";
        JSch jsch = new JSch();
        Session session = jsch.getSession(user, host, 22);
        UserInfo ui = new MyUserInfo();
        session.setUserInfo(ui);
        session.connect();

        Channel channel = session.openChannel("exec");
        ((ChannelExec) channel).setCommand(command);

        channel.setInputStream(null);
        channel.setOutputStream(null);
        channel.connect();
        channel.disconnect();
        session.disconnect();


The above code works perfectly. But can i get the status of invoke signal? I mean is there any way so that I can get that whether shell script is invoked successfully or not? Also I don't want to wait for its execution and STDOUT/STDERR.
 
-Ravi Joshi


------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d


_______________________________________________
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users