I have a Unix Script that has several exit in the middle. each returning seperate
exit codes.
I have to catch all the exit's and perform an operation say "Mail the status code" before the actual code completes.
How can i do this in KSH ?
I have a Unix Script that has several exit in the middle. each returning seperate
exit codes.
I have to catch all the exit's and perform an operation say "Mail the status code" before the actual code completes.
How can i do this in KSH ?
Introduce a function to catch all the exit codes.
Something like
EXIT_CODE=""
function assembleExitCode
{
EXIT_CODE="${EXIT_CODE} $@"
}
At every place where you are looking for an exit code, invoke the function as
assembleExitCode $?
At the end of the code,
if [[ x"$EXIT_CODE" != x ]] ; then
echo "Mail status"
fi ;
case $? in
1) echo "Exit message1";;
2) echo "Exit message2";;
.
.
.
esac
trap "command" EXIT
man ksh trap