email report

This commit is contained in:
Ste Vaidis 2022-12-23 17:05:38 +02:00
parent 78faefc54a
commit 96fb2f1373

View File

@ -1,12 +1,14 @@
#!/bin/bash #!/bin/bash
IFS=$'\n' IFS=$'\n'
LOG='/root/backup-usb.log' NOW=$(date +"%Y-%m-%d_%H:%M")
LOG="/root/backup_$NOW.log"
USB_DISK="" USB_DISK=""
USB_PARTITION="" USB_PARTITION=""
USB_MOUNT="/mnt/usb" USB_MOUNT="/mnt/usb"
LUKS_PASS_URL="192.168.1.199:9999/andthepasswordis" LUKS_PASS_URL="192.168.1.199:9999/andthepasswordis"
LUKS_PASS="" LUKS_PASS=""
MAIL_RECIPIENT="ste.vaidis@gmail.com"
function log() { function log() {
echo -e "`date +'%d/%m/%Y %H:%M:%S'` | $1" echo -e "`date +'%d/%m/%Y %H:%M:%S'` | $1"
@ -38,7 +40,6 @@ function get_luks_password() {
fi fi
} }
function find_usb() { function find_usb() {
for DISK in `ls -l /dev/disk/by-id/usb* | grep -v part | awk -F/ '{print $NF}'`; do for DISK in `ls -l /dev/disk/by-id/usb* | grep -v part | awk -F/ '{print $NF}'`; do
DEV="/dev/$DISK" DEV="/dev/$DISK"
@ -196,7 +197,15 @@ function check_depentencies() {
done done
} }
function send_mail() {
COPIED=$( cat ${LOG} | grep "Number of created files:" | awk {'print $5'} )
DELETED=$( cat ${LOG} | grep "Number of deleted files:" | awk {'print $5'} )
SUBJECT="${COPIED} files copied, ${DELETED} files deleted"
echo "Backup Report" | mutt -s $SUBJECT -F /etc/muttrc $MAIL_RECIPIENT -a $LOG
}
function main () { function main () {
rm $LOG -rf
log "" log ""
log "BACKUP STARTED ====================" log "BACKUP STARTED ===================="
log "SOURCE : $SRC" log "SOURCE : $SRC"
@ -211,6 +220,7 @@ function main () {
fi fi
statistics_usb statistics_usb
umount_usb umount_usb
send_mail
fi fi
fi fi
fi fi