ssh - How to use "sudo su" in java command -
i trying use sshxcute class connect unix machine , kill zombie processes.but below program hangs. please me out.
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 connbean instance parameter sshexec static method getinstance(connbean) retrieve singleton sshexec instance sshexec ssh = sshexec.getinstance(cb); // connect 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(); } }
i dunno ur environments but.. try one.
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();
Comments
Post a Comment