Email Notifications on Cron Bash Error Only cp mv rsync

Wondering if anyone can point me to an example of how to setup a bash script that executes cp mv and rsync commands and only sends an email if there were errors with any of those commands and what the errors are. In addition it should email if the cron event to execute the script fails, or in other words if the bash script doesn't run at all or exits prematurely with an error.

Thank you!

All of those commands return non-zero on error.

See rsync(1) - Linux manual page near the bottom for error return values.

rsync has a huge range of uses and many, many options. mv and cp work the same, i.e., return non-zero on error. We cannot provide guidance on setting up a script, but generally you can set up an error checking function in bash like this

#!/bin/bash
# bash function to check for errors - name capitalized to stand out in code
# usage:
# called  right after a cp, mv or rsync command, 
#   LINENO is an internal bash variable,  $? is the exit status of the command.
#   
#   ERR_CHK $LINENO $? is how to call this
ERR_CHK()  
{
    if [ $2 -gt 0 ]; then
       echo "Script name failed at line $1" | mailx -s 'cron job failure' me@myemailaddress.com
       exit 1
    fi    
}

# later on in the script call it
cp somefile anotherfile
ERR_CHK $LINENO $?

mv something somewhere 
ERR_CHK $LINENO $?

rsync [ a huge bunch of options and parameters ]
ERR_CHK $LINENO $?

Have fun.