Going Linux

   for computer users who just want to use Linux to get things done

Automating Updates using Aptitude and Cron

Updated: 17-Nov-2012

Do you run Ubuntu or a derivative of Ubuntu? Do you find yourself accepting everything every time the update manager notifies you that updates are available? If so, perhaps you might benefit from automating those updates. Of course you want to ensure that the automation takes care of answering any prompts with a "yes" and that kernel and distribution upgrades don't happen automatically.

Knightwise has provided an excellent summary of this topic on his blog so we'll let you read the details there. ( post) Knightwise links to his source, Kevin van Zonnevelds blog, which adds the ability to create a log of the update process just in case something goes wrong. Read that post as well for even more details. We have included our crontab entry below for your reference.

If you need a brief crontab tutorial or would like to know what else you can automate with crontab, we have articles for both on this website:

The cron job

This is what I added to my crontab. Notice all the comments to help me remember what I did and where I put the log file. Note that, since aptitude needs to run as root, you will want to use the command sudo crontab -e instead of simply crontab -e to edit your cron job.

# Auto update with aptitude. Does not upgrade distribution or kernel
# ref:
#0 1 * * * /usr/bin/aptitude -y update && /usr/bin/aptitude -y safe-upgrade
0 1 * * * (/usr/bin/aptitude -y update && /usr/bin/aptitude -y safe-upgrade) 2>&1 >> /var/log/auto_update.log
#“-y” makes sure that you don’t have to type YES at the end of the command.
#"safe-upgrade" will skip kernel updates and distribution upgrades
#"2>&1 >> /var/log/auto_update.log" forwards all messages (errors (2), and standard (1)) to a logfile
#"&&" links two commands together, but will not execute the second if the first one failed.

Site Created with theMaker for Linux

Theme music for the Going Linux podcast is generously provided by Mark Blasco.
Creative Commons License Going Linux Podcast by Larry Bushey is licensed under a Creative Commons Attribution 4.0 International License.