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
IFS=$'\n'
LOG='/root/backup-usb.log'
NOW=$(date +"%Y-%m-%d_%H:%M")
LOG="/root/backup_$NOW.log"
USB_DISK=""
USB_PARTITION=""
USB_MOUNT="/mnt/usb"
LUKS_PASS_URL="192.168.1.199:9999/andthepasswordis"
LUKS_PASS=""
MAIL_RECIPIENT="ste.vaidis@gmail.com"
function log() {
echo -e "`date +'%d/%m/%Y %H:%M:%S'` | $1"
@ -38,7 +40,6 @@ function get_luks_password() {
fi
}
function find_usb() {
for DISK in `ls -l /dev/disk/by-id/usb* | grep -v part | awk -F/ '{print $NF}'`; do
DEV="/dev/$DISK"
@ -196,7 +197,15 @@ function check_depentencies() {
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 () {
rm $LOG -rf
log ""
log "BACKUP STARTED ===================="
log "SOURCE : $SRC"
@ -211,6 +220,7 @@ function main () {
fi
statistics_usb
umount_usb
send_mail
fi
fi
fi