I wrote some bash script that does some backup job. I run the script with errexit and pipefail so I won't miss any error. The thing I want now is the script sending me an email in case an error occures. I got this working. But I want the scripts errors to be included in the email body. How can I do this?
here is the script:
#!/bin/bash
# exit script if an error occures
set -o errexit
# even exit if an error in passed through a pipe
set -o pipefail
trap 'ERRORMESSAGE_HERE | mailx -s "Something went wrong on srv-002" mymail@mycompany.ch' ERR
# the backup job here
# if script reaches this point everything went perfectly good
echo "all good!"
Thanks a lot for your help!