Hello,

I use yum-cron always in CHECK_ONLY (or DOWNLOAD_ONLY) modes, and would
prefer if it would not send mail if nothing has changed since the last
run.  Sometimes there are reasons why I want to delay applying some
available updates even for weeks, and the daily mails of them tend to
become annoying which then again leads to them being ignored and
possibly some other updates than the ones I wanted to delay being
missed.  I suppose I could use exclude= to suppress output for some
packages but somehow I don't feel comfortable with that and I don't know
if one can use exclude= for specific NEVRs, i.e. if I want to not be
notified of a particular NEVR of something, but would like to be
notified about newer ones of that N.

The attached patch is mostly for discussion purposes, I haven't tested
this particular one actually at all, but I have done some testing of
similar changes applied over CentOS 5.x's yum-cron and they seem to work
nicely for me.  Please note that as said, I run only in
CHECK_ONLY/DOWNLOAD_ONLY modes so maybe the patch is not something that
is not desirable in all other modes (or maybe it doesn't hurt, haven't
thought about it much at all).

Thoughts, comments?
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
_______________________________________________
Yum-devel mailing list
Yum-devel@lists.baseurl.org
http://lists.baseurl.org/mailman/listinfo/yum-devel

Reply via email to