My ongoing experiences with Ubuntu, and later Mythbuntu, as a media center with MythTV. I'm also using the system for a virtual machine server, a mediawiki server and a general all around home infrastructure base.

Sunday, March 29, 2009

Redoing auto-updates to reduce email

I've gotten a little tired about the amount of email I receive daily from my automatic daily package updates, particularly now that I've installed logwatch, which provides me with much of the same information.

I have two types of machines that I want to update:
  1. Virtual machines that I just want to auto update and I don't want to hear about it unless there is an error. Yes, I understand I risk configuration problems, but so far this hasn't been a problem so I'm happy living on the edge.

  2. My key server and my laptop. On these machines I do the conservative download the packages and once a week, on the weekend, I sit down and manually install them. (If some critical security update occurs, I assume I will hear about it via other channels and jump in manually).
On all systems: make cron-apt quiet
I started by editing cron-apt configuration on all my systems and configuring it so it only sends email on errors by changing the MAILON value to "error":
# vi /etc/cron-apt/config
# grep ^MAILON /etc/cron-apt/config
MAILON="error"
Key Server and Laptop
Then I turned to my server system and laptop. I want to run cron-apt daily and then once per week send me a reminder to update (assuming there is something to update, which generally there is). I could just run cron-apt weekly, but this way if there is a critical security update, it will already be downloaded and I just have to install it.

To run cron-apt dailly, I add it to /etc/cron.daily:
# ln -s /usr/sbin/cron-apt /etc/cron.daily/
Then I created the following script to send me a weekly reminder me to install the upgrades (based on the script from this page):
# vi /etc/cron.weekly/show-upgrades
# chmod +x show-upgrades
And here is the script:
#!/bin/sh
tmpFile=`mktemp`
apt-get --simulate dist-upgrade > $tmpFile 2>&1
if test $? -ne 0 ; then
echo "Error running apt-get --simulate dist-upgrade:"
cat $tmpFile
rm -f $tmpFile
exit 1
fi
grep Inst $tmpFile > /dev/null
if test $? -eq 0; then
echo "Upgrades are pending. Run 'apt-get dist-upgrade' to install."
grep Inst $tmpFile
echo
echo "Full output:"
cat $tmpFile
fi
rm -f $tmpFile
exit 0
Virtual Machines
Now, turning to my virtual machines. What I wanted here was automatically daily upgrade of all new packages with no output unless there was an error. This involved editing to the auto-update script I had created previously:
# vi /etc/cron.daily/auto-update
Here is the script:
#!/bin/bash
/usr/sbin/cron-apt
tmpFile=`mktemp`
/usr/bin/apt-get -y dist-upgrade > $tmpFile 2>&1
if test $? -ne 0 ; then
echo "Error doing '/usr/bin/apt-get -y dist-upgrade':"
cat $tmpFile
fi
rm -f $tmpFile

No comments: