Yum: Checking for updates.

Here’s a quick script you can put in your cron rotation to check and see if there are any updates available and what they are:


#!/bin/bash

yum_output=/tmp/yum-check-update-output.txt
python=/usr/bin/python1.5
yum=/usr/bin/yum

$python $yum check-update > $yum_output

yum_return_code="$?"

case $yum_return_code in
100)
# Packages available for update.
echo '********************************************************'
echo "The following packages need to be udpated on $HOSTNAME"
echo '********************************************************'
echo ''
cat $yum_output
;;
0)
# No packages available for update.
;;
*)
echo "YUM: Undefined return code: $yum_return_code ."
exit 1
esac

exit 0

This entry was posted in General, work and tagged , , , , . Bookmark the permalink.

3 Responses to Yum: Checking for updates.

  1. Nat says:

    what would you change to make this work for apt? And is it possible to have it send an email? just pondering

  2. augie says:

    Well that depends on what kind of return codes apt has. Yum will return “100″ if there are packages to be updated and “0″ if not.

    Typically in /etc/crontab you can set where ou want any output from scripts to go to; usually it is set to go to “root”, so it will mail it’s output out, but yes you could pipe the output to “mail” or “sendmail” and mail it off that way.

  3. Nat says:

    hmm interesting. ill have to try setting that up. cool script though, thanks.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>