Skip to main content
tone down.
Source Link
c32hedge
  • 2.7k
  • 19
  • 39

Execute Unix commands using Jsch maven

I'm trying use this code for performing the following steps, but it's not working!.

  1. String command1 = "ls -ltr"
  2. String command2 = "cd /test/user/"
  3. String command3 = "./test.sh"

Reference Link.

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.

Execute Unix commands using Jsch maven

I'm trying use this code for performing the following steps but it's not working!

  1. String command1 = "ls -ltr"
  2. String command2 = "cd /test/user/"
  3. String command3 = "./test.sh"

Reference Link.

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 command doesn't work! Nothing happens-- stuck here! Could anyone help out with this problem?

Execute Unix commands using Jsch maven

I'm trying use this code for performing the following steps, but it's not working.

  1. String command1 = "ls -ltr"
  2. String command2 = "cd /test/user/"
  3. String command3 = "./test.sh"

Reference Link.

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);

But the last line doesn't work--nothing happens.

modified question
Source Link
Bharat Mane
  • 6.8k
  • 11
  • 41
  • 69

Execute unixUnix commands using Jsch maven

I'm trying use this code for performing the following steps but itsit's not working!

  1. String command1 = "ls -ltr"
  2. String command2 = "cd /test/user/"
  3. String command3 = "./test.sh"

http://www.journaldevReference Link.com/246/java-program-to-run-shell-commands-on-ssh-enabled-system

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");

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);

// From above command does work! It lists the files. ((ChannelExec)channel).setCommand(command2); // Above command doesn't work! Nothing happens-- stuck here! Could anyone help out with this problem?

Execute unix commands using Jsch maven

I'm trying use this code for performing the following steps but its not working!

  1. String command1 = "ls -ltr"
  2. String command2 = "cd /test/user/"
  3. String command3 = "./test.sh"

http://www.journaldev.com/246/java-program-to-run-shell-commands-on-ssh-enabled-system

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 command doesn't work! Nothing happens-- stuck here!

Execute Unix commands using Jsch maven

I'm trying use this code for performing the following steps but it's not working!

  1. String command1 = "ls -ltr"
  2. String command2 = "cd /test/user/"
  3. String command3 = "./test.sh"

Reference Link.

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 command doesn't work! Nothing happens-- stuck here! Could anyone help out with this problem?

Source Link

Run unix commands using Jsch maven

Execute unix commands using Jsch maven

I'm trying use this code for performing the following steps but its not working!

  1. String command1 = "ls -ltr"
  2. String command2 = "cd /test/user/"
  3. String command3 = "./test.sh"

http://www.journaldev.com/246/java-program-to-run-shell-commands-on-ssh-enabled-system

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 command doesn't work! Nothing happens-- stuck here!