java - Running multiple commands as root with Jsch() -
im having problems running multiple commands root user, using exec channel. dont exceptions, second command not being executed reason.
here code
try { jsch jsch = new jsch(); string command1 = "touch 1.txt; touch 2.txt"; //"sudo chmod 755 script.sh; sudo sh script.sh"; string user = "user"; string host = "10.68.228.140"; string privatekey = "/home/user/.ssh/blabla"; jsch.addidentity(privatekey); system.out.println("identity added "); session session = null; while(session == null) { thread.sleep(1000); session = jsch.getsession(user, host); } system.out.println("session created "); java.util.properties config = new java.util.properties(); config.put("stricthostkeychecking", "no"); session.setconfig(config); while(!session.isconnected()) { thread.sleep(1000); session.connect(); } system.out.println("session connected....."); channel channel = session.openchannel("sftp"); channel.connect(); channelsftp sftpchannel = (channelsftp)channel; sftpchannel.put("/home/user/script.sh", "/home/user"); sftpchannel.disconnect(); channel.disconnect(); channel channel1 = session.openchannel("exec"); ((channelexec) channel1).setcommand(command); channel1.connect(); channel1.disconnect(); session.disconnect(); } catch(jschexception e){ e.printstacktrace(); } catch(sftpexception se){ se.printstacktrace(); } catch(exception e) { } so if leave this, fine. 2 files created on remote machine. if give command commented line, script not executed. (it changes mode) give me please? i've been stuck day now.
Comments
Post a Comment