title: Running multiple commands as root with Jsch()
body: <p>Im having problems running multiple commands as the root user, using the <strong>exec</strong> channel. I dont get any exceptions, however the second command is not being executed for some reason.</p>
  
  <p>Here is my code</p>
  
  <pre><code>try {
    JSch jsch = new JSch();
  
    String command1 = "touch 1.txt; touch 2.txt";
              //"sudo chmod 755 script.sh; sudo sh script.sh";
    String user = "user";
    String host = "10.68.228.140";
    String privateKey = "/home/user/.ssh/blabla";
  
    jsch.addIdentity(privateKey);
    System.out.println("identity added ");
  
  
    Session session = null;
    while(session == null) {
      Thread.sleep(1000);
      session = jsch.getSession(user, host);
    }
    System.out.println("session created ");
  
    java.util.Properties config = new java.util.Properties();
    config.put("StrictHostKeyChecking", "no");
    session.setConfig(config);
  
    while(!session.isConnected()) {
      Thread.sleep(1000);
      session.connect();
    }
  
    System.out.println("session connected.....");
  
    Channel channel = session.openChannel("sftp");
    channel.connect();
    ChannelSftp sftpChannel = (ChannelSftp)channel;
  
    sftpChannel.put("/home/user/script.sh", "/home/user");
    sftpChannel.disconnect();
    channel.disconnect();
  
    Channel channel1 = session.openChannel("exec");
    ((ChannelExec) channel1).setCommand(command);
    channel1.connect();
    channel1.disconnect();
  
    session.disconnect();
  
  } catch(JSchException e){
      e.printStackTrace();
  } catch(SftpException se){
      se.printStackTrace();
  }
  catch(Exception e) {
  
  }
  </code></pre>
  
  <p>So if I leave it like this, everything is fine. The two files are created on the remote machine. But if I give as command the commented line, then the script is not executed. (It changes only mode)
  Could you give me a help please? I've been stuck with this all day now.</p>