rsync email notification on success and failure + Log

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


Hi,

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
RC=$?
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
    )
else
   touch ${DST}/.gwdg-mirror
fi
echo "==== end   ======== RC=${RC} ============ ${DAT1} ${DAT2}" >>${PROT}

MAILIT=yes
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
     MAILIT=no
   fi
fi

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}
#else
#  mail -s"${SUBJ} (RC=${RC}) __nomail__" ${MAILTO} <${PROT}
fi


Viele Gruesse
Eberhard Moenkeberg (emoenke at gwdg.de, em at kki.org)

-- 
Eberhard Moenkeberg
Arbeitsgruppe IT-Infrastruktur
E-Mail: emoenke at gwdg.de      Tel.: +49 (0)551 201-1551
-------------------------------------------------------------------------
Gesellschaft fuer wissenschaftliche Datenverarbeitung mbH Goettingen (GWDG)
Am Fassberg 11, 37077 Goettingen
URL:    http://www.gwdg.de             E-Mail: gwdg at gwdg.de
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