Setup Auto Updating Apt-get Update/Upgrade with Logging

Here’s some quick steps on how to setup automatic apt-get upgrade and apt-get update on your ubuntu server, with the capability of logging and sending someone of your choosing a notification of the updates and what the output was.

I pieced this together from various sources around the web into a step by step quick tutorial both for myself, and others to use to make it easier when wanting to set this up across servers.

It’s a pretty handy addition to any administration tool kit as it cuts down on time ssh’ing in and manually running this, and is especially useful because it’s got logging so you only have to login if there was an issue!

** nb assumes a proper postfix / default setup.


** nb assumes a proper postfix / default setup.

1) SSH to server

2) login / su to root

3) issue these commands:

# nano /root/autoupd

4) paste these items in

ourtime=`date +"%m-%d-%y"`
echo "APT UPDATE RESULTS:" >> ${tmpfile}
echo "*---*" >> ${tmpfile}
aptitude update >> ${tmpfile} 2>&1
echo "" >> ${tmpfile}
echo "APT UPGRADE RESULTS:" >> ${tmpfile}
echo "*---*" >> ${tmpfile}
aptitude -y full-upgrade >> ${tmpfile} 2>&1
echo "" >> ${tmpfile}
echo "APT CLEAN RESULTS:" >> ${tmpfile}
echo "*---*" >> ${tmpfile}
aptitude clean >> ${tmpfile} 2>&1
mail -s "[${ourtime}] - [${hostname} patches]" root < ${tmpfile}
rm -f ${tmpfile}

5) issue this for your aliases file

# nano /etc/aliases

6) make sure this exists:


replacing with your proper email address, obviously.

7) run newaliases to ensure functionality

# newaliases

8) restart postfix

# service postfix restart

9) test the script

# chmod +x /root/autoupd
# /root/autoupd

10) you should now have an email in your inbox with the results, if not grab a coffee and start troubleshooting.

11) now you want to make this run daily by copying it to your daily cron directory and make it executable again, just incase something changed.

# cp /root/autoupd /etc/cron.daily/autoupd
# chmod +x /etc/cron.daily/autoupd

12) that’s it, wait for the email notifications!

No comment yet, add your voice below!

Add a Comment

Your email address will not be published. Required fields are marked *

Comment *

Name *
Email *