Ubuntu Automatic Updates

At work, we mainly use RedHat Enterprise Linux. We have a RedHat Network subscription to manage pushing or viewing updates and that all works fairly well. I decided to use Ubuntu Linux on my Linode. Since it's not a desktop, I need a way to know when there are updates. The desktop versions will alert you when updates are available. I'm not going to blindly script cron to install updates for me, so I put together a short script to let me know when they are ready and to cache the packages on the server.

The Ubuntu site does have a page describing how to do weekly updates, but my script suits my needs. I created a crontab entry to call the script below. It'll only output info, which causes cron to send an email, when there are applicable updates. Maybe it'll be helpful to other people as well.

# Script to check for updates.  If any are available, print to stdout
# and download packages.


# Update package info
apt-get update -qq

# Cache available updates
apt-get upgrade -s > $tempfile

# Check to see if any updates are applicable.
egrep "^Inst " $tempfile > /dev/null
if [ $? -eq 0 ]; then
   # Download updates
   apt-get upgrade -dyqq

   # Print available package info so it gets emailed.
   cat $tempfile

# Remove tempfile and exit
rm -f $tempfile
exit 0

Tags: , , , ,

2 Responses to “Ubuntu Automatic Updates”

  1. Matt Says:

    Or, you could just "sudo apt-get install apticron" :)
    It will email you when there are updates available, including the changelog information for those updates.

  2. path Says:

    Yea, I've been trying out apticron the last couple weeks and it is pretty nice. Thanks for pointing that out!

Leave a Reply