The Hacker’s Blog

Your friendly neighborhood hacker!

Tuesday, July 8, 2008

Automatically upgrading Ubuntu Linux!

Ubuntu has quickly became one of my favorite Linux distros to use, however, its slowly falling behind to others such as Gentoo, Debian and Slackware. I still use it on my home file server, though. It seems to work really well for that.

The Problem

The big problem for me is keeping my server up to date. I always like to be running the most current version of all software available, even if it is on a server. I’ve upgraded to Hardy Heron and am looking forward to the release of Intrepid Ibex.

I run on a DSL connection so my bandwidth is pretty limited. I normally don’t like to have to put up with a slow connection because I’m downloading updates to my server. This leaves me with the option to download the updates at night while I’m asleep. However, its kind of hard to start a download at 3:00 A.M. while you’re asleep, isn’t it? No, not really. Here’s how.

The Solution

There are two things that every Ubuntu user should know about. The first is using apt to update your system and install software. The second is cron. Cron is a utility/daemon that is used to run specified scripts at a certain time.

The first step to setting up your computer to auto update itself is figuring out what command you need to update and upgrade while allowing everything to be installed. It looks something like the following:

apt-get -y update && apt-get -y –force-yes upgrade && apt-get -y –force-yes dist-upgrade

If you run that manually, it will fetch the information for all packages to be updated and then begin installing them.

The second and probably most complicated step is setting up cron. Start by creating a file called apt-get.cron. In this file you need to enter the time and command you want to run. Let’s say we want to update our computer every Monday at midnight. The first part of our file should look like this:

0 0 * * Mon

This tells cron to run on the 0th minute of the 0th hour of every Monday of every Month. The next step is to specify the user (which needs to be root for apt to work correctly). Adding in the user and command should leave you with something looking like:

0 0 * * Mon root apt-get -y update && apt-get -y –force-yes upgrade && apt-get -y –force-yes dist-upgrade

Next, add the cron file to cron by running (as root)

crontab apt-get.cron

Keep in mind, that running the previous command will remove all other cron jobs in your crontab.

The Glorious End

Now your computer should be all set up for auto updating. Give it a try. Sit in front of your computer and wait until your script runs. Then check the logs to make sure it ran. Or, if you want, just leave it be and check it some other time.

Related Posts

posted by prime at 6:10 pm  

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress