本帖最后由 tmily 于 2015-02-26 15:02:57 编辑

解决方案 »

  1.   

    1.开源的ssh jar。
    2.或者自己写agent利用socket通信
      

  2.   

    Runtime.getRuntime().exec这个方法不好么?
      

  3.   

    可以试试Apache Commons exec library
    package testShellScript;import java.io.IOException;
    import org.apache.commons.exec.CommandLine;
    import org.apache.commons.exec.DefaultExecutor;
    import org.apache.commons.exec.ExecuteException;public class TestScript {
        int iExitValue;
        String sCommandString;    public void runScript(String command){
            sCommandString = command;
            CommandLine oCmdLine = CommandLine.parse(sCommandString);
            DefaultExecutor oDefaultExecutor = new DefaultExecutor();
            oDefaultExecutor.setExitValue(0);
            try {
                iExitValue = oDefaultExecutor.execute(oCmdLine);
            } catch (ExecuteException e) {
                // TODO Auto-generated catch block
                System.err.println("Execution failed.");
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                System.err.println("permission denied.");
                e.printStackTrace();
            }
        }    public static void main(String args[]){
            TestScript testScript = new TestScript();
            testScript.runScript("sh /root/Desktop/testScript.sh");
        }
    }
    http://stackoverflow.com/questions/525212/how-to-run-unix-shell-script-from-java-code