#/usr/bin/ksh
myscript.sh
success=$?
if [ $success -eq 0 ]; then
echo "script successfull"
else
echo "Script failed!!!" | mail -s "Myscript" \ me@somehwere.com
fi
NOTE: myscript.sh must explicitly return a value eg. "return 0" for success or anything else for failure.
Scripts that finish without a return statement return whatever the last statement returns. If you use return within a function, it will just exit the function. (In contrast, the statement exit N exits the entire script, no matter how deeply you are nested in functions.)