0

I am trying to execute this command on my router via SSH and Java, but I am getting this error. What is causing this error? If I log directly into my router the command works no problem!

Here is error I get:

MacBook-Pro:Test_SSH owner$ java -cp .:/Users/owner/Downloads/jsch-0.1.55.jar com.company.Main username password 192.168.5.1 vbash: configure: command not found exit-status: 127

Here is my code:

package ssh;
import com.jcraft.jsch.*;
import java.io.InputStream;

public class Shell{
public static void main(String[] arg){

try{
    JSch jsch = new JSch();

      Session session = jsch.getSession(arg[0],arg[2] , 22);
      java.util.Properties config = new java.util.Properties();
      config.put("StrictHostKeyChecking", "no");
      session.setPassword(arg[1]);
    session.setConfig(config);
    session.connect();

      String command = "configure";
      Channel channel = session.openChannel("exec");
      ((ChannelExec) channel).setCommand(command);
      channel.setInputStream(null);
      ((ChannelExec) channel).setErrStream(System.err);
      InputStream in = channel.getInputStream();

      channel.connect();

      byte[] tmp = new byte[1024];
      while (true)
      {
        while (in.available() > 0)
        {
          int i = in.read(tmp, 0, 1024);
          if (i < 0)
            break;
          System.out.print(new String(tmp, 0, i));
        }
        if (channel.isClosed())
        {
          System.out.println("exit-status: " + channel.getExitStatus());
          break;
        }
        try
        {
          Thread.sleep(1000);
        }
        catch (Exception ee)
        {
        }
      }

      channel.disconnect();
      session.disconnect();
    }
    catch (Exception e)
    {
        System.out.println("sdfdfdf");
      System.out.println(e.getMessage());
    }
 }


}
Doctor Ford
  • 440
  • 1
  • 5
  • 17
  • Try providing the full path to the `configure` command. – KevinO Mar 29 '19 at 15:05
  • @KevinO - what is the full path of the configure command? If I log into my router all I have to do is type configure, so I am uncertain what the full path is... – Doctor Ford Mar 29 '19 at 15:09
  • 1
    I wouldn't know what the full path would be. On the router, since it seems like it is giving a shell if you do a standard ssh, you _might_ be able to do "which configure" or "type -f configure" to get the path. You might look in /bin, /usr/bin, /sbin/, /usr/sbin -- the usual suspects. – KevinO Mar 29 '19 at 15:13
  • @KevinO - if I use the command Whereis to try to locate it - this is the output I get. Which to me shows that it should work in the "home" directory admin@ubnt:~$ whereis configure configure: – Doctor Ford Mar 29 '19 at 21:52
  • Why `whereis`? What does it prove? `whereis whatever` always prints `whatever:`, no matter if `whatever` is any real file. -- Both @KevinO and the answer to the duplicate question suggest using `which`. – Martin Prikryl Mar 30 '19 at 05:34

0 Answers0