I’ve been looking for a good way of keeping my Debian-systems up-to-date. However, there are no really good way of doing this, from what I’ve found. There is a problem with letting APT doing both update and installation/upgrade, without having the user to manually intervine. There are no way of the user to know what packages are installed, and if the system needs further configuration or even an restart (if for example the kernel itself is updated/patched).
So, the most practical solution I’ve come up with, is to be informed when updates are available, and then doing the actual upgrade myself. One way of doing this is to use the package cron-apt, which just downloads the new version of the package, but never installs them. It then sends a mail to a predefined user, telling him what packages are ready to be installed.
However, I ended up with writing my own little shell-script. It’s very basic, but does what it’s supposed to.
Update: I’ve made some changes to the script. During the night I was spammed with 19 mails saying that there were updates available, and I only need one mail to tell me that. So, the script no uses a temporary file to find out wether an mail has already has been sent or not. Also, I made som minor adjustments to the code in general.
#/bin/sh
# Debian update script, By G�an Sandahl goran@gsandahl.net http://gsandahl.net
# This script will inform you if there are updated available for your host.
# The script should be kind of self-explanatory. Run it in cron every 10 minutes.
# Set the email-adress that should recieve the update-information. Also, the file
# that contains the last sent mail. When updates are available, a mail is sent only
# if the mail that will be sent isn’t the same as the one in the file. That way
# we won’t get spammed if updates are available, but we are unable to update them.
mail_adress=”goran@gsandahl.net”;
lastsentmail=”/tmp/.lastsentmail.tmp”
# String of how the output is like when there are no updates
matchstring=”0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.”
result=$(echo “This probe was done: `date`” && echo “—” && apt-get update \
&& echo “—” && apt-get –simulate upgrade);
if !(echo “$result” : grep “$matchstring” &> /dev/null) && \
!(grep “$result” cat $lastsentmail &> /dev/null)
then
echo “$result” : mail -s “ `hostname`” $mail_adress
echo “Packages for update, mail sent”
echo “$result” > $lastsentmail
fi
Here’s how the mail looks like: http://gsandahl.net/pictures/debian-update.sh.png
I run this script on all of my Debian-boxes, and they send me an email when updates are available. The mail include the output of both apt-get update and apt-get –simulate upgrade. I recommend placing it in cron, somewhat like this:
twosome# echo “0-59/10 * * * * /home/neewt/debian-update.sh >> /dev/null” >> ~/temp_file
twosome# crontab ~/temp_file
This will run the script every 10 minutes, as the user you entered those commands. I run them as root, because no other user is by default allowed to issue apt-get. However, it might be smarter to give a user sudo-rights (by adding them to the group wheel) and allow them to only run this script with root-permissions. That’s probably how I will do it.
If you don’t have an MTA (Mail Transfer Agent, and is needed for the ‘mail’-command) at the server you intend to run this, I can suggest a tiny MTA. It’s in Debian Stable as the package ssmtp. Very easy to setup, and very easy to maintain.
Please tell me what you think, and/or if you do this another way.