Thread: Cron and email
View Single Post
  #7   (View Single Post)  
Old 23rd August 2019
fvgit's Avatar
fvgit fvgit is offline
Spikes in tights
 
Join Date: May 2016
Location: perl -MMIME::Base64 -le 'print decode_base64("U2hlcndvb2QgRm9yZXN0")'
Posts: 314
Default

Have you tried rewriting your script to sth. like this?
Code:
#!/bin/sh
backup() {
    mount /dev/sd1a /mnt/
    /usr/local/bin/rsync -avh --exclude-from=/home/stan/rsync.exclude /home/stan /mnt/
    /usr/local/bin/rsync -avh /etc /mnt/
    /usr/local/bin/rsync -avh /var //mnt/
    cd /home/stan/
    umount /mnt/
}
backup | mail -s "backup log" root
sleep 5
shutdown -p now
I haven't tested this. But basically this should put the backup routine into a separate function backup() whose output is then mailed (by the backup script not by cron) to root before shutdown occurs. Optionally you can put a higher value on sleep, just in case, to insure the mail delivery process can complete. Although it's probably not necessary.
Reply With Quote