I am trying to connect my remote unix machine and execute some ssh commands using a java program.
connection = new Connection(hostname);
connection.connect();
boolean isAuthenticated = connection.authenticateWithPassword(username, password);
if (isAuthenticated == false)
throw new IOException("Authentication failed.");
Session session = connection.openSession();
session.execCommand("sudo su - weblogic");
Here it needs password again & ofcrs, I can't provide because there is no terminal. So created a user.sh file @ my unix user home direcotry (/home/..../bharat) with below content.
echo <mypassword> | sudo -S su - weblogic
sudo -S su - weblogic
but now if I call bash user.sh like below
session.execCommand("bash user.sh");
after logging in with my user in java, it gives below error & could not figure out the resolution for this yet.
sudo: sorry, you must have a tty to run sudo
sudo: sorry, you must have a tty to run sudo
Please help :)
The Response of Send("cd /u02/app/oracle/xyz/admin/domains/11.1.1.9/xxxx_xx_xxx_xxx.domain/shared/logs/xxxx"); is below -
Highlighted Red ==> shows the response, I am getting as of now.
Highlighted Blue ==> Expected response.
Highlighted Green ==> works fine if I send 4 smaller commands by splitting the same command.