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