rsync email notification on success and failure + Log

Eberhard Moenkeberg emoenke at
Tue Dec 29 17:29:40 MST 2009


On Wed, 30 Dec 2009, Sébastien Arpin wrote:

> I have a bash script for rsync that should tranfer all my filer from one 
> drive to the other.
> I would like to know how I can make the script sending me an email after 
> the script is run and be able to know if it was a success or not and 
> also if possible to include the log file.

I do it this way:

rsync ${ALLOPTS} ${SRC} ${DST} >>${PROT} 2>&1
DAT2="`date +%y%m%d.%H%M`"
if test "${RC}" = "0" -o "${RC}" = "23"; then
   grep "^Total file size: " ${PROT} | \
    ( read a b c d e
      echo "${DAT2} ${NAM} size: $d bytes." >>${DST}/.gwdg-mirror
   touch ${DST}/.gwdg-mirror
echo "==== end   ======== RC=${RC} ============ ${DAT1} ${DAT2}" >>${PROT}

if [ "${RC}" = "0" ]; then
   NUMFIL=`grep "^Number of files transferred:" ${PROT} | \
             (while read n o f t X; do echo -n ${X}; done)`
   if [ "${NUMFIL}" = "0" ]; then

if [ "${MAILIT}" = "yes" ]; then
   V1="is uptodate"
   V2="is a hard link"
   V3="^backed up "
   V4="^deleting "
   grep -v "${V1}\|${V2}\|${V3}\|${V4}" ${PROT} | \
     mail -s"${SUBJ} (RC=${RC})" ${MAILTO}
#  mail -s"${SUBJ} (RC=${RC}) __nomail__" ${MAILTO} <${PROT}

Viele Gruesse
Eberhard Moenkeberg (emoenke at, em at

Eberhard Moenkeberg
Arbeitsgruppe IT-Infrastruktur
E-Mail: emoenke at      Tel.: +49 (0)551 201-1551
Gesellschaft fuer wissenschaftliche Datenverarbeitung mbH Goettingen (GWDG)
Am Fassberg 11, 37077 Goettingen
URL:             E-Mail: gwdg at
Tel.:   +49 (0)551 201-1510            Fax:    +49 (0)551 201-2150
Geschaeftsfuehrer:           Prof. Dr. Bernhard Neumair
Aufsichtsratsvorsitzender: Dipl.-Kfm. Markus Hoppe
Sitz der Gesellschaft:     Goettingen
Registergericht:           Goettingen  Handelsregister-Nr. B 598

More information about the rsync mailing list