SCIENTIFIC-LINUX-DEVEL Archives

October 2011

SCIENTIFIC-LINUX-DEVEL@LISTSERV.FNAL.GOV

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Kevan Benson <[log in to unmask]>
Reply To:
Kevan Benson <[log in to unmask]>
Date:
Wed, 26 Oct 2011 15:16:45 -0700
Content-Type:
multipart/mixed
Parts/Attachments:
text/plain (1436 bytes) , yum-autoupdate.patch (2970 bytes)

Attached are patches to extend the functionality of yum-autoupdate to 
allow pre/post actions to be defined for more custom usage.

Here's a short list describing the enhancement and what it allows:

* Defined through $PRERUN and $POSTRUN variables in sysconfig file.

* Action only taken when variable not empty.

* $PRERUN/$POSTRUN are eval'd to allow access to parent script variables 
(with forethought you can get access to $TEMPFILE and $TEMPMAILFILE in 
case you want to alter/parse their data), or to just run an external 
program.

* $POSTRUN happens before mailing in case it should affect the content 
or whether mail is sent.

* Output of $PRERUN is prepended to yum output in mail, and $POSTRUN 
output is appended to yum output that is mailed.

* Output honors $SENDONLYERRORS by filtering STDOUT when true.

* With DEBUG=true will print status messages to STDOUT about the 
PRERUN/POSTRUN output.

* Behaviour without setting PRERUN/POSTRUN is identical to before.

I tried to match the existing coding style and what appeared to be the 
design goals as closely as possible, but please let me know if anything 
looks incorrect. The hope is that this gets included upstream (you) so 
we don't have to roll our own RPM and exclude the upstream version 
(yours).  Obviously we have the ability to fall back to this if this 
patch is deemed undesirable, but hopefully if there's a problem I can 
address it, as it's a fairly simple enhancement.

-Kevan
-Sonic.net



diff -rU2 yum-autoupdate-2/etc/cron.daily/yum-autoupdate yum-autoupdate-2.new/etc/cron.daily/yum-autoupdate --- yum-autoupdate-2/etc/cron.daily/yum-autoupdate 2011-08-15 08:19:27.000000000 -0700 +++ yum-autoupdate-2.new/etc/cron.daily/yum-autoupdate 2011-10-26 14:47:46.545195998 -0700 @@ -112,5 +112,7 @@   TEMPFILE="`mktemp /tmp/yum.temp.XXXXXXXXXX`"   TEMPCONFIGFILE="`mktemp /tmp/yum.temp.config.XXXXXXXXXX`" + TEMPPRERUNFILE="`mktemp /tmp/yum.temp.prerun.XXXXXXXXXX`"   TEMPMAILFILE="`mktemp /tmp/yum.temp.mail.XXXXXXXXXX`" + TEMPPOSTRUNFILE="`mktemp /tmp/yum.temp.postrun.XXXXXXXXXX`"   TEMPRANDFILE="`mktemp /tmp/yum.temp.rand.XXXXXXXXXX`"   TODAY="$(date +%Y-%m-%d)" @@ -132,4 +134,21 @@   check_yum   + #**************************** + #PRERUN + #**************************** + if [ "$PRERUN" != "" ]; then + if [ "$DEBUG" = "true" ] ; then + echo "Executing PRERUN: $PRERUN" + fi + if [ "$SENDONLYERRORS" = "true" ] ; then + eval $PRERUN >/dev/null 2> $TEMPPRERUNFILE + else + eval $PRERUN &> $TEMPPRERUNFILE + fi + if [ "$DEBUG" = "true" ] ; then + echo "PRERUN output:" + cat $TEMPPRERUNFILE + fi + fi      #**************************** @@ -204,4 +223,21 @@    #****************************   + #**************************** + #POSTRUN + #**************************** + if [ "$POSTRUN" != "" ]; then + if [ "$DEBUG" = "true" ] ; then + echo "Executing POSTRUN: $POSTRUN" + fi + if [ "$SENDONLYERRORS" = "true" ] ; then + eval $POSTRUN >/dev/null 2> $TEMPPOSTRUNFILE + else + eval $POSTRUN &> $TEMPPOSTRUNFILE + fi + if [ "$DEBUG" = "true" ] ; then + echo "POSTRUN output:" + cat $TEMPPOSTRUNFILE + fi + fi     #**************************** @@ -223,5 +259,5 @@   echo " /bin/mail -s \"YUM:$HOSTNAME:$TODAY\" $MAILLIST "   fi - /bin/mail -s "YUM:$HOSTNAME:$TODAY" $MAILLIST < $TEMPMAILFILE + cat $TEMPPRERUNFILE $TEMPMAILFILE $TEMPPOSRUNTFILE | /bin/mail -s "YUM:$HOSTNAME:$TODAY" $MAILLIST   fi   else @@ -231,5 +267,5 @@   echo " /bin/mail -s \"YUM:$HOSTNAME:$TODAY\" $MAILLIST "   fi - /bin/mail -s "YUM:$HOSTNAME:$TODAY" $MAILLIST < $TEMPMAILFILE + cat $TEMPPRERUNFILE $TEMPMAILFILE $TEMPPOSRUNTFILE | /bin/mail -s "YUM:$HOSTNAME:$TODAY" $MAILLIST   fi   fi @@ -244,5 +280,7 @@   yum -e 0 -d 0 clean packages   yum -e 0 -d 0 provides xyz > /dev/null 2>&1 + rm -f $TEMPPRERUNFILE   rm -f $TEMPMAILFILE + rm -f $TEMPPOSTRUNFILE   rm -f $TEMPCONFIGFILE   rm -f $TEMPRANDFILE diff -rU2 yum-autoupdate-2/etc/sysconfig/yum-autoupdate yum-autoupdate-2.new/etc/sysconfig/yum-autoupdate --- yum-autoupdate-2/etc/sysconfig/yum-autoupdate 2011-08-15 07:55:49.000000000 -0700 +++ yum-autoupdate-2.new/etc/sysconfig/yum-autoupdate 2011-10-26 15:13:39.262214560 -0700 @@ -45,2 +45,9 @@  DEBUG="false"   +# PRERUN +# The name of an executable or commands to run prior to updating (but after sleep) +PRERUN="" + +# POSTRUN +# The name of an executable or commands to run after updating (but before mailing) +POSTRUN=""

ATOM RSS1 RSS2