# report a backup cronjob, attaching logs set -e finish() { status=$? if [[ $status = 0 ]]; then STATUS="SUCCESS (status $status)" else STATUS="FAILURE (status $status)" fi mail user@example.com \ -s "Backup job report on $(hostname): ${STATUS}" \ --content-type 'text/plain; charset=utf-8' \ -A"$LOG_FILE" <<< 'The log report is in the attachment.' } trap finish EXIT do-long-backup-cmd-here