1
我試圖通過Java程序執行多個bash命令,該程序使用JSch連接到SSH。但sudo
登錄後,我無法執行任何bash命令。從我讀過的sudo
登錄後,我們進入了一個子shell。我希望使用單個頻道。對於下一步該怎麼做我無能爲力。sudo登錄後使用Java JSch程序執行多個bash命令
ChannelExec chnlex=(ChannelExec) session.openChannel("exec");
InputStream in = chnlex.getInputStream();
BufferedReader br=new BufferedReader(new InputStreamReader(in));
chnlex.setCommand("sudo -u appbatch -H /opt/apptalk/local/bin/start_shell.sh -c <<exit");
chnlex.connect();
System.out.println("channel connection done");
String msg=null;
while((msg=br.readLine())!=null){
System.out.println(msg);
}
chnlex.disconnect();
System.out.println("channel disconnected");
也有人可以告訴我如何寫這些bash命令在一個單獨的函數或文件?