Whenever the shell script is invoked by the scheduler the command execution return code is always captured as 0(Success).
If the same shell script is executed in command line via unix terminal, the command execution return code's are captured properly.
For example:
ls -ltr es_wrong_file ----> file not available in the filesystem
echo $? ----> return code $? will be 2(other than 0)
If the above example is executed via scheduler (which in turn invokes the script) - the return code is captured as 0 (success)
whereas if its a directly command line execution of the same script then the return code is captured properly as "2"
---------- Post updated at 06:43 AM ---------- Previous update was at 06:40 AM ----------
Oracle scheduler is used
Unix flavor is AIX6.1
shell used - ksh
It could simply mean that your script generates the file "es_wrong_file" at run-time and ls is able to list it at that particular time. Check if this file is being written to in your script. This could also be an intermediate file which your script could be cleaning up before termination.
So, don't leave people guessing and post the script if you can.
The script would have to exit with a non-zero exit code.
ls -ltr es_wrong_file ; REPLY=$?
exit ${REPLY}
It would indeed be better to test whether the file exists rather than letting the command fail. Use syntax appropriate to your O/S (many do not have "-e").