On Wed, Sep 03, 2003 at 02:40:12PM +1200, Jim Cheetham wrote:
> However, I guess the "full" version should restate a previous comment
> this morning, which is that you should at least automate the collection
> of updates, if not the actual installation.
> 
> For Debian, I generally do half that job, with a
> apt-get update && apt-get --simulate upgrade
> 
> I suppose you could do 
> apt-get update && apt-get --download-only upgrade
> 
> Any advice for improving on this invocation welcome :-)

# Check for upgraded packages.

and:

-----8<-----
#!/bin/sh
# Filename: checkupdates.sh
# Purpose: automatically check for updates, and mail me when there are
#          some to attend to. Add to root's crontab with something like:
#
#   30  1   *  *  *     /root/bin/checkupdates.sh
#

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

HOSTNAME=`hostname -f`
TMPFILE=`tempfile`

apt-get update > $TMPFILE 2>&1
if [ $? -ne 0 ]; then
  mail -s "[$HOSTNAME] APT update failed, check manually" root < $TMPFILE
  rm -f $TMPFILE
  exit 0
fi

apt-get -s upgrade > $TMPFILE 2>&1
if [ $? -ne 0 ]; then
  mail -s  "[$HOSTNAME] APT simulated upgrade failed, check manually" root < $TMPFILE
  rm -f $TMPFILE
  exit 0
fi

if ! grep -qE '^(Inst|Conf) ' $TMPFILE; then
  # No packages need upgrading
  rm -f $TMPFILE
  exit 0
fi

UPGRADES="$(awk '/^Inst / { print $2 }' $TMPFILE | sort | sed 's/^/    /')"

apt-get -dyu upgrade > $TMPFILE 2>&1
if [ $? -ne 0 ]; then
  SUBJECT="[$HOSTNAME] APT package download failed, check manually"
else
  SUBJECT="[$HOSTNAME] Updated packages pending"
fi

mail -s "$SUBJECT" root << EOM
[$HOSTNAME] The following packages are pending an upgrade:
$UPGRADES

Please log in and run 'apt-get upgrade'

Download output follows:
$(cat $TMPFILE)

-- 
$0
EOM

rm -f $TMPFILE

exit 0
# EOF
-----8<-----

Cheers,
Mike.
-- 
Mike Beattie <[EMAIL PROTECTED]>                      ZL4TXK, IRLP Node 6184

    "Sometimes I think that the surest sign that intellegent life exists
   elsewhere in the universe is that none of it has tried to contact us."

Reply via email to