Go to the Going Linux home page
Going Linux

The Podcast
Receive new episodes automatically.
Subscribe for free:
Copy and paste this link into your podcatcher to subscribe to the mp3 feed mp3 feed
Copy and paste this link into your podcatcher to subscribe to the ogg feed ogg  feed

Subscribe via iTunes

Creative Commons License
This work
is licensed under a
Creative Commons Attribution 3.0 License.


Going Linux
Practical Information for Using Linux To Get Things Done
 Home Tab  Show Notes Tab  Articles Tab  Screencasts Tab  About Us Tab  
Automating Updates using Aptitude and Cron

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. (Knightwise.com 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:
Automating backups using rsync, bash and cron
Shell Scripting Tutorials

Top

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: http://knightwise.com/automate-your-ubuntu-updates-with-a-simple-command/
#
#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.

Top
Search our site

Google



Updated 21-Nov-2012 Valid HTML 4.01 Transitional Valid CSS! An interoperable Web page