I am trying to execute multiple bash commands through a Java program which connects to a SSH using JSch. But after sudo
login, I am unable to execute any bash commands. From what I have read, after sudo
login, we enter into a sub-shell. I wish to use a single channel. I am clueless as to what to do next.
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");
Also could anyone tell me how to write these bash commands in a separate function or file?