[Yum] [Repost] Additional script "yum-check" to run from cron

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi!

Sorry for reposting, fixed out bugs and made it cleaner, all three 
possible actions have been tested through cron.daily now and work as 
expected. Config defaults now to autoupdate.

The idea behind it, let yum check for updates from cron and send mail if 
there are updates available or yum couldn't run for one or another problem.

Any thoughts?


/usr/bin/yum-check:

#!/bin/bash
#
# Name:         yum-check
# Author:       Michael Heiming
# Function:     Run from cron to check for yum updates
#               and mail results
# Version:      0.7 (initial)				- 2005-03-11
#     		0.8 randomize startup (cron only) 	- 2005-03-12
# 		0.9 bug fix 				- 2005-03-14
# Config:       /etc/sysconfig/yum

# Pull in sysconfig settings

. /etc/sysconfig/yum-check

maila=${MAILTO:=root}
yumdat="/tmp/yum-check-update.$$"
yumb="/usr/bin/yum"

if ! [ -t ]
then
         num=$RANDOM
         let "num %= ${RANGE:=1}"
         sleep $num
fi

$yumb check-update >& $yumdat

yumstatus="$?"

case $yumstatus in
         100)
         cat $yumdat |\
         mail -s "Yum: ${HOSTNAME} updates available!" $maila
         exit 0
;;
         0)
         # Only send mail if debug is turned on
         if [ ${CHECKWRK} = "yes" ];then
         cat $yumdat |\
         mail -s "Yum: Check succeded ${HOSTNAME} no new patches." $maila
         fi
         exit 0
;;
         *)
         # Unexpected yum return status
         (echo -e "Yum: Undefined return status: ${yumstatus}\n" && \
         [ -e "${yumdat}" ] && cat "${yumdat}" )|\
         mail -s "Yum: Alert ${HOSTNAME} problems running yum." $maila
esac

[ -e "${yumdat}" ] && rm ${yumdat}




/etc/cron.daily/yum.cron:


#!/bin/sh

# Pull in sysconfig settings

. /etc/sysconfig/yum-check


if [ -f /var/lock/subsys/yum ]; then

         if [ ${CHECKONLY} = "yes" ];then

                 /usr/bin/yum-check
         fi
         else


         /usr/bin/yum -R 10 -e 0 -d 0 -y update yum
         /usr/bin/yum -R 120 -e 0 -d 0 -y update
fi



/etc/sysconfig/yum-check (defaults to autoupdate now):

# "yes" -> check for updates and mail only if patches are available
# "no" -> enable autoupdate if /var/lock/subsys/yum is in place
CHECKONLY="no"
# defaults to root, leave empty if .forward/alias in place for root
MAILTO=""
# Set to "yes" for debugging only! You get a mail for each run!
CHECKWRK="no"
# Seconds to randomize startup, if running from cron against public
# yum server, to balance load, default to 1h.
RANGE="3600"


Regards and keep the great work!


Michael Heiming


[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux