zypper-update-report (was: patch2mail for SLES10)

Well, after some more refining I think I finally have a script I ain’t never gonna touch again (unless something breaks, which can happen quick as we all know).

The script now uses a sysconfig file for the common settings (like sender, receipents, categories to scan for), so it may be deployed en mass.

/etc/sysconfig/zypper-update-report

/usr/local/sbin/zypper-update-report

2 thoughts to “zypper-update-report (was: patch2mail for SLES10)”

  1. I edited your code to send html email and the update info

    #!/bin/bash

    [ -f /etc/sysconfig/zypper-update-report ] || exit 1

    source /etc/sysconfig/zypper-update-report

    # Temporary files
    ZYPP_LIST=”$( mktemp /tmp/zypper-list.XXXXXX )”
    ZYPP_DETAILS=”$( mktemp /tmp/zypper-details.XXXXXX )”
    TMP=”$( mktemp /tmp/zypper-report.XXXXXX )”
    zypper pch 2>/dev/null > $ZYPP_LIST

    # Figure out how much updates are still pending PENDING=”$( cat $ZYPP_LIST | grep “| Needed” | wc -l )”

    if [ $PENDING -eq 0 ] ; then
    exit 0
    fi

    echo “TO: $RECEIPENTS” > $TMP
    echo “From: $FROM” >> $TMP
    echo “Subject: [$( date +%F )] Update report for $(domainname -f) ” >> $TMP
    echo ‘MIME-Version: 1.0’ >> $TMP echo ‘Content-type:text/html;charset=iso-8859-1’ >> $TMP
    echo ” >> $TMP echo ” Pending updates for $( domainname -f ) on $( date )” >> $TMP
    echo ” >> $TMP echo ‘Package’ >> $TMP
    echo ‘Needs Reboot’ >> $TMP
    echo ‘Update Info’ >> $TMP
    echo ‘Atom’ >> $TMP
    echo ‘‘ >> $TMP

    for severity in $CLASSES; do
    PACKAGES=”$( cat $ZYPP_LIST | egrep “${severity}(.*)| Needed” |
    cut -d| -f2 | sed “s,^ ,,” | sort -u )”
    [ -n “$PACKAGES” ] && echo
    [ -n “$PACKAGES” ] && echo ” Category: $severity”
    echo ‘

    for package in $PACKAGES; do
    zypper patch-info $package 2>/dev/null > $ZYPP_DETAILS
    echo ”
    echo “”
    echo ” $package”
    echo ”
    echo ” $( cat $ZYPP_DETAILS |
    grep “Reboot Required:” | sed -e “s,Reboot Required: ,,” )”
    echo “”
    echo ‘


    for atom in $( cat $ZYPP_DETAILS | grep “^atom:” | cut -d -f2 |
    sort ); do
    # Let’s check whether or not the package listed in atom is
    # installed. If so, echo the atom, otherwise skip it
    RPM_STATUS=$( rpm -qi $atom )
    if [ “$RPM_STATUS” != “package $atom is not installed” ] ; then
    echo ” – $atom”
    fi
    done
    done
    echo ”
    done >> $TMP
    echo ” >> $TMP

    if [ -n “$RECEIPENTS” ] ; then
    cat $TMP |
    sendmail $RECEIPENTS
    fi

    trap ‘rm -f “$TMP” “$ZYPP_LIST” “$ZYPP_DETAILS” >/dev/null 2>&1’ 0 trap “exit 2” 1 2 3 15

    # vim: set tw=80 ts=2 sw=2 et softtabstop=2

  2. I had some bug in the other code. This is the one fixed.
    # Figure out how much updates are still pending
    PENDING=”$( cat $ZYPP_LIST | grep “| Needed” | wc -l )”

    if [ $PENDING -eq 0 ] ; then
    exit 0
    fi

    echo “TO: $RECEIPENTS” > $TMP
    echo “From: $FROM” >> $TMP
    echo “Subject: [$( date +%F )] Update report for $(domainname -f) ” >> $TMP
    echo ‘MIME-Version: 1.0’ >> $TMP
    echo ‘Content-type:text/html;charset=iso-8859-1’ >> $TMP
    echo ” >> $TMP
    echo ” Pending updates for $( domainname -f ) on $( date )” >> $TMP
    echo ” >> $TMP
    echo ‘Package’ >> $TMP
    echo ‘Needs Reboot’ >> $TMP
    echo ‘Update Info’ >> $TMP
    echo ‘Atom’ >> $TMP
    echo ” >> $TMP

    for severity in $CLASSES; do
    echo ‘
    PACKAGES=”$( cat $ZYPP_LIST | egrep “${severity}(.*)| Needed” |
    cut -d| -f2 | sed “s,^ ,,” | sort -u )”
    [ -n “$PACKAGES” ] && echo
    [ -n “$PACKAGES” ] && echo ” Category: $severity”
    echo ‘

    for package in $PACKAGES; do
    zypper patch-info $package 2>/dev/null > $ZYPP_DETAILS
    echo ”
    echo “”
    echo ” $package”
    echo ”
    echo ” $( cat $ZYPP_DETAILS |
    grep “Reboot Required:” | sed -e “s,Reboot Required: ,,” )”
    echo “”
    echo ‘


    for atom in $( cat $ZYPP_DETAILS | grep “^atom:” | cut -d -f2 |
    sort ); do
    # Let’s check whether or not the package listed in atom is
    # installed. If so, echo the atom, otherwise skip it
    RPM_STATUS=$( rpm -qi $atom )
    if [ “$RPM_STATUS” != “package $atom is not installed” ] ; then
    echo ” – $atom”
    fi
    done
    done
    echo ”
    done >> $TMP
    echo ” >> $TMP

    if [ -n “$RECEIPENTS” ] ; then
    cat $TMP |
    sendmail $RECEIPENTS
    fi

    trap ‘rm -f “$TMP” “$ZYPP_LIST” “$ZYPP_DETAILS” >/dev/null 2>&1’ 0
    trap “exit 2” 1 2 3 15

    # vim: set tw=80 ts=2 sw=2 et softtabstop=2

Leave a Reply

Your email address will not be published. Required fields are marked *

I accept that my given data and my IP address is sent to a server in the USA only for the purpose of spam prevention through the Akismet program.More information on Akismet and GDPR.

This site uses Akismet to reduce spam. Learn how your comment data is processed.