I am trying to execute a Linux shell script in a remote server from Java program using JSch. I was successfully able to execute the script when I logged in to the server and run the script using putty, but when I am running through my Java program, it is giving the following error:
"<<script_name>>: Warning distribution home directory (HOME variable) is not defined or can't be read"
Below is my Java program:
JSch jsch = new JSch();
session = jsch.getSession(username, remoteHost);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword(password);
session.connect();
channelExec = (ChannelExec) session.openChannel("exec");
InputStream in = channelExec.getInputStream();
channelExec.setCommand("sh "+scriptFileName);
channelExec.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
result.add(line);
}
exitStatus = channelExec.getExitStatus();
Please help. Iam using Spring Boot in my project.