#!/bin/bash DIR=$(realpath $(dirname $0)) source $DIR/.env # Exit the script and sendmail # $1 : exit code # $2 : message leave(){ subject="[ `hostname` ] Backup" if [ $1 -eq 0 ] then subject="$subject successful" else subject="$subject failed" fi cat << EOF | /usr/sbin/sendmail -t root Subject: $subject The backup on `hostname` ended with code $1. $2 For more information see /var/log/bckp.log Best regards, EOF exit $1 } if [ `whoami` != "root" ] then echo "this script must be run as root" exit 1 fi