0

I'm using net.neoremind.sshxcute SSH Java API library to connect to a sftp server and execute a shell script present on that server.

My Shell Script does a simple job of moving files from that SFTP location to a HDFS location on some other machine.

Currently, there's no way to report if any of the files are not moved due to any reason such as connection failure, file with illegal name, empty file etc.

I wonder, how can I show that set of information for each failed file move from shell command back to Java code ?

This is my sample code :

// e.g sftpScriptPath => /abc/xyz
// sftpScriptCommand => sudo ./move.sh
// arguments => set of arguments to shell script.
task = new ExecShellScript(sftpScriptPath, sftpScriptCommand, arguments);
result = m_SshExec.exec(task);
if(result.isSuccess && result.rc == 0)
{
     isSuccessful = true;
     s_logger.info("Shell script executed successfully");
     s_logger.info("Return code : " + result.rc);
     s_logger.info("Sysout : " + result.sysout);
}
else
{
     isSuccessful = false;
     s_logger.info("Shell script execution failed");
     s_logger.info("Return code : " + result.rc);
     s_logger.info("Sysout : " + result.sysout);
}
1
  • From shell script you can only get a return value indicating success or failure, but you could arrange your script to write reasons of every failures to a log file, when the script reports failure, your Java code could learn from that log file these reasons. Commented Mar 4, 2014 at 6:54

1 Answer 1

1

The Result object returned from the exec method call includes:

  • exit status or return code (Result.rc),
  • standard output (stdout) (Result.sysout),
  • standard error (stderr) (Result.error_msg), and
  • an indication of success, based on return code and output (Result.isSuccess).

So, if you are committed to the current method of executing a shell script using the sshxcute framework, then the simplest way would be to have the move.sh script provide information about any failures while moving files. This could be done via a combination of return codes and standard output (stdout) and/or standard error (stderr) messages. Your Java code would then obtain this information from the returned Result object.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.