We have an use case to transfer > 4GB data file from a sftp site to server box. We have decided to create a java service which will invoke a shell script that interns enter into the sftp site and path and get the file to the target destination.
We have wrote the following code to invoke shell script from Java file.
Process proc = null;
String command = "/mnt/hmdata/loadTest.sh";
System.out.println("passing command::" + command);
try {
Runtime rt = Runtime.getRuntime();
proc = rt.exec(command.trim());
boolean status = proc.waitFor `enter code here` (45, TimeUnit.SECONDS);
LOGGER.log(Level.INFO, "Shell Called successfully");
if (status) {
msg = "Shell Called successfully";
} else {
msg = "Error while calling Shell";
}
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
proc.destroy();
}
The shell script is like that
sshpass -p '<password>' scp -r <userid>@<host>:/finint/inbound/financial/tenv/edw_osccl/* .
Once I am calling my java service, our service unable to start the shell. On contrary same shell is working fine from server command prompt. We are running our program from Unix.
Can you anyone please suggest the solution.