I have a bash script and would like to add in the ability to trap for both EXIT and ERR conditions. The structure is currently
trap cleanup EXIT
function notify(reason) {}
function build {}
function dbops {}
function deploy {}
function cleanup {}
notify('start') \
&& build \
&& dbops \
&& deploy \
&& notify('finished');
What is the recommended way to add in a trap for an error and (optionally) capture the exit reason, and send that via the notify function? Right now all the cleanup does is delete the lock file on EXIT.
I want to be able to send a notify(reason)
message out to slack if the script fails unexpectedly, but not send it on normal EXIT.
Is my execution chaining going to interfere with properly trapping for errors?