I have been suggested to open a new thread on how to send mails to internet addresses.
My script is using mail to report problems coming from a backup script. The idea is to get an email when a problem happens or when backup finishes succesfully.
This is how my code looks like concerning the usage of mail
#!/bin/bash # The scripts should always start with the external devices unmounte. # 1. First checks that the device is not mounted (that should be always) # 2. Mounts the device # 3. Copy the files # 4. Unmounts the device # 5. Send emails at the moment a failure appears or at the end when everything was succesful SCRIPTNAME="BACKUPOFDATA.SH" MOUNTPOINT=/mnt/BckpMeasurements MAILADDRESS="firstname.lastname@example.org" # 1. MOUNT=`mount | grep $MOUNTPOINT` if ! test -n "$MOUNT" ; then #2. mount $MOUNTPOINT # In case the above did not work. I need to send email with message and stop immediately. How I check that the mount was done? else echo "Device already mounted! Why? Check if something wrong happened with the backup scripts" | mail -r \ $MAILADDRESS -s "Backup Scripts Failed" $MAILADDRESS exit fi # Do the Copy of The Files # 3. # rsync command goes here # if rsync failes send an email to me too # How to check that rsync returned succesfully # End of Copy of the files # 4. # Unmount the Device umount $MOUNTPOINT MOUNT=`mount | grep $MOUNTPOINT` if test -n "$MOUNT" ; then echo "Device Failed to be unmounted! Why? Check if something wrong happened with the backup scripts" | mail -r \ $MAILADDRESS -s "Backup Scripts Failed" $MAILADDRESS exit fi # I want to send me also an email with backup sucessful # That should be when rsync returned succesfully and the unmount was too. # 5. echo "Script Name: Data and Time. Rsync finished successfully. Device was also unmounted Successfully. Send a kiss to robin_lista" | mail -r \ $MAILADDRESS -s "Backup Scripts Finished at" $MAILADDRESS