I have a sub sh file which puts receives an input of local directory and path to the remote directory and sends the file to the remote directory. If the remote path is invalid the error cannot be detected.Sample content inside the sh script:sftp XXX@XXX.XXX.XXX.XXX <<==cd $remote_dir                      <= error happens herelcd $local_dir                      <= error did not happen so the return code resetsput a.tarbye==$result=$?return $resultSome application calls the sh file, then the return code is used to judge if the file was successfully sent or not. If yes, the local file is backed up somewhere then deleted.The problem is the shell returns zero even if the sending of the file failed. The file really was not copied, you can see that the error happens when you do the command manually, the path is not found is displayed in the screen, but when running as a job, it fails. I know another way to do this is to do two steps, first check if the path exists, then output to a log file and check if the log contains an error, if there are no error then you can call the sftp put shell script. I was wondering if there is another way.
Capture errors in a SFTP script
scripting;sftp;error handling