我正在尝试使用sshxcute类连接到我的unix机器并杀死僵尸进程。但是以下程序挂起。请帮帮我。
public class SSHexecute {
/**
* @param args
*/
public static void main(String[] args) { // TODO Auto-generated method stub
ConnBean cb = new ConnBean("stage2c7400.qa.com", "rmeena", "sample");
// Put the ConnBean instance as parameter for SSHExec static method getInstance(ConnBean) to retrieve a singleton SSHExec instance
SSHExec ssh = SSHExec.getInstance(cb);
// Connect to server
ssh.connect();
CustomTask sampleTask = new ExecCommand("sudo su -; ps -ef |grep defunct");
//CustomTask sampleTask1 = new ExecCommand("ls -lrt");
try {
Result s = ssh.exec(sampleTask);
System.out.println("************"+s.sysout+"***********");
} catch (TaskExecFailException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ssh.disconnect();
}
}
答案 0 :(得分:0)
我不喜欢你的环境,但.. 试试这个。
Process p = new ProcessBuilder("sudo").start();
p.getOutputStream().write("su -; ps -ef | grep defaunct".getBytes());
p.getOutputStream().write("exit\n".getBytes());
p.getOutputStream().flush();
p.getOutputStream().close();