我已经编写了一个代码,在服务器中执行SSH并运行带有参数的Java文件。无法在远程服务器的SSH中执行我的命令
我面对的问题是,代码成功执行SSH,但之后不运行该命令。奇怪的是,如果我从服务器单独运行命令它的作品。对此有任何建议吗? 以下是代码:
public void getSSH(String code, String newCode, JspWriter out){
try{
File f = new File("/usr/site/html/Output.txt");
BufferedWriter output = new BufferedWriter(new FileWriter(f));
String Servers[] = {"[email protected]","[email protected]","[email protected]","[email protected]"};
for(int i =0;i<Servers.length && i<1 ;i++){
Process p = Runtime.getRuntime().exec("/usr/site/swapimages.sh "+Servers[i]+" '/root/testRemote.sh "+ code+" "+ newCode+"'");
out.println("/usr/site/swapimages.sh "+Servers[i]+" '/root/testRemote.sh "+ code+" "+ newCode+"'"+"<br>");
Utils.waitFor(10000);
}
}
}
我也一直建议JSch但还没有研究它。
它会在ssh会话结束后运行命令吗? – trutheality
只有一个... exec(),所以我只希望它运行一个命令(... swapimages.sh)。你是否期望它也在同一个单独的exec()中运行testRemote.sh?也许我错过了一些东西,但不会需要第二个...... exec()for testRemote.sh? – Straff
是啊,我在运行testRemote.sh在同一个exec命令 但它的工作时,我只是跑在服务器上.. – uppaljaskaran