diff --git a/yum-cron/yum-cron.sh b/yum-cron/yum-cron.sh index e300fa7..64cef96 100755 --- a/yum-cron/yum-cron.sh +++ b/yum-cron/yum-cron.sh @@ -157,14 +157,25 @@ fi } >> $YUMOUTPUT 2>&1 +SUMFILE=/var/cache/yum/yum-cron.last +touch $SUMFILE +[[ -x /sbin/restorecon ]] && /sbin/restorecon $SUMFILE + +OLDSUM="$(cat $SUMFILE)" +NEWSUM="$(sha1sum -b $YUMOUTPUT | cut -d' ' -f1)" +if [[ "$MAIL_ONLY_IF_CHANGED" == "yes" && "$OLDSUM" == "$NEWSUM" ]]; then + rm -f $YUMOUTPUT + exit 0 +fi + if [[ ! -z "$MAILTO" && -x /bin/mail ]]; then # If MAILTO is set, use mail command for prettier output. [[ -s "$YUMOUTPUT" ]] && \ mail -s "System update: $SYSTEMNAME" $MAILTO < $YUMOUTPUT && \ - rm -f $YUMOUTPUT + echo "$NEWSUM" > $SUMFILE && rm -f $YUMOUTPUT else # The default behavior is to use cron's internal mailing of output. - cat $YUMOUTPUT && rm -f $YUMOUTPUT + cat $YUMOUTPUT && echo "$NEWSUM" > $SUMFILE && rm -f $YUMOUTPUT fi exit 0 diff --git a/yum-cron/yum-cron.sysconfig b/yum-cron/yum-cron.sysconfig index 4c8c40d..b26c021 100644 --- a/yum-cron/yum-cron.sysconfig +++ b/yum-cron/yum-cron.sysconfig @@ -27,6 +27,9 @@ DOWNLOAD_ONLY=no # (Valid options: yes|no) CHECK_FIRST=no +# Send mail only if nothing changed since the last run. +# (Valid options: yes|no) +MAIL_ONLY_IF_CHANGED=no # Yum error level. The practical range is 0-10, where 0 means print # only critical errors, and 10 means print all errors, even ones that diff --git a/yum.spec b/yum.spec index b78a9f6..8e52f99 100644 --- a/yum.spec +++ b/yum.spec @@ -284,6 +284,7 @@ exit 0 %dir %{_datadir}/yum-cron %{_datadir}/yum-cron/update.yum %{_datadir}/yum-cron/cleanup.yum +%ghost /var/cache/yum/yum-cron.last %if %{yum_updatesd} %files updatesd