wiki:centos:update-notification

Wäre es nicht schön, wenn man eine Email bekommen könnte, sollten Updates vorliegen?

Hier die Lösung

update-notification.sh
count_file="/usr/local/bin/.updates"
email_addresses="someone@somewhere.gmx"
 
packages=`yum check-update --quiet | cut -d " " -f 1 | sed -e '/./!d' | sort | uniq`
count_packages=`echo $packages | wc -w`
 
if [ ! -e $count_file ]
then
        echo 0 > $count_file
fi
 
#old_packages=`cat $count_file`
if [ `cat $count_file` = $count_packages ]
then
        exit 0
fi
 
echo $count_packages > $count_file
 
if [ $count_packages -gt 0 ]
then
        #Updates werden heruntergeladen
        yum --downloadonly update --quiet
        if [ ! $? = 0 ]
        then
                for address in $email_addresses
                do
                        echo -e "Das System `hostname` hat $count_packages Updates\nDas Herunterladen war fehlerhaft!\n\n$packages" \
                                | mail -s "Warning!! $count_packages Updates available for `hostname`, Download fehlerhaft" $address
                done
        else
                for address in $email_addresses
                do
                        echo -e "Das System `hostname` hat $count_packages Updates\nDas Herunterladen ergab keine Fehler\n\n$packages" \
                                | mail -s "$count_packages Updates available for `hostname`" $address
                done
        fi
fi
Geben Sie Ihren Kommentar ein. Wiki-Syntax ist zugelassen:
  ____      __   __    ____   ____
 / __ \ __ / /  / /   /  _/  / __/
/ /_/ // // /  / /__ _/ /   / _/  
\___\_\\___/  /____//___/  /___/
 
  • wiki/centos/update-notification.txt
  • Zuletzt geändert: 2016/05/16 20:50
  • von wikiadmin