Automatic update and upgrade
Fetching and installing security updates and fixes is a priority for any server administrator.
However, this can take time so why not have your server send you an email when an update is available?
This tutorial is based on an Ubuntu server but should work perfectly well on any Debain based server.
The basic command to update the available packages from the sources list is:
apt-get update
and a check to see if there are any packages to be upgraded would be:
apt-get upgrade
More often than not this will take a couple of minutes and results in no packages being available. A bit of an anti-climax and waste of time.
Let's set the server to do this automatically and to send you an email if there are any updates available.
As this will run with no interaction we will set a cron job to run as the root user and set it to run at 23.55hrs everyday. However, we only want an email if there are updates available and not to disturb you if there are none.
For the update and upgrade commands to run silently we need to add the -qq option to the commands. This ensures there is no output unless an update is available:
apt-get -qq update
apt-get -qq --simulate upgrade
The 'simulate' option does just that. It will go through the motions of an upgrade and only if there is a positive result will there be any output. Setting a 'MAILTO' in the crontab will ensure any output is emailed to you.
To set this up, edit the root crontab:
sudo crontab -e
My root crontab had nothing in it and looks like this:
The sytax is pretty simple and when completed the entries will be:
MAILTO="webmaster@yourdomain.com"
# Check for updates at 2355hrs everyday
55 23 * * * apt-get -qq update && apt-get -qq --simulate upgrade
The MAILTO contains the email address you want any message to go to.
The line starting with '#' is a comment and is ignored by crontab but gives an idea as to what follows. Commenting like this is very useful - a quick glance will tell you what you were doing 6 months ago when you set this up.
The final line gives the commands and what time to run them.
Save the entry and you're done. Each day at 2355hrs, your server will silently run the commands and only send you an email if there are upgrades available.
PickledOnion.
Digg it |
del.icio.us |
reddit |
StumbleUpon

Subscribe to Feed
Article Comments:
BobbyL 05 Jul, 2007
Do you need to set up a mail system in order for this to work. What mail system do you recommend?
PickledOnion 05 Jul, 2007
Bobby,
As the email is being sent and not received by the server you do not need a full mail system installed and configured.
I have a base postfix (with default options) installation which does just fine for outgoing email. I do not have any mail ports open as, again, it's being sent not received by the server.
PickledOnion.