Requirement is to run the following unix command sudo su - fwt****app
in java.
Below is my code:
Channel channel=session.openChannel("exec");
String[] cmd = {"/bin/bash","-c","echo password| sudo -S -p su - fwt***app; ls"};
((ChannelExec)channel).setCommand(cmd.toString());
InputStream in=channel.getInputStream();
OutputStream out=channel.getOutputStream();
((ChannelExec)channel).setErrStream(System.err);
channel.connect();
out.write(("Password"+"\n").getBytes());
out.flush();
Have tried other method as well, which is ((ChannelExec)channel).setCommand(sudo -S -p su - fwt***app)
, it didn't worked.
I have tried switching to other user by using command su - fwtveguiapp Password: But got response as - su: Sorry It needs to run using both sudo and su commands. As both sudo and su commands are required I am getting a syntax error in sudo command. Other references helps only with sudo command hence they were not helpful in my case.