Below is a quick hack to have your Ubuntu machine automagically update for you at a pre-specified time. This includes the “update”, “upgrade”, “dist-upgrade” and “autoclean” commands. The scheduling is taken care of by cron, our trusty always-on-time friend.
sudo crontab -e
It is important that you use sudo at this point. The command will need super-user priveleges so the cron listing needs to be setup as the root user.
0 0 * * * aptitude -y update && aptitude -y upgrade && aptitude -y dist-upgrade && aptitude -y autoclean
The above line represents the listing put into the crontab file. Here is a quick explanation of the five fields you can specify for the date and time. (The above executes daily at midnight)
minute - hour - day of month - month - day of week
After you have specified the appropriate time and date for your system simply save the file and your system will now automagically upgrade at the time specified. These upgrades include regular updates, kernel updates, security updates, etc. Also, the “autoclean” command removes old packages from your system after they are no longer needed.
Of course, if you prefer not to have cron take care of everything (if you’d still like to be somewhat hands-on) you could simply run the command in a single line:
sudo aptitude -y update && sudo aptitude -y upgrade && sudo aptitude -y dist-upgrade && sudo aptitude autoclean
technorati tags:ubuntu, breezy, dapper, edgy, update, dist-upgrade, security, cron, aptitude
Pingback: Planeta Debian » Christer Edwards: Package Management with APT : Ubuntu (all versions)
This may sound stupid, but I did this and it failed.
I realised at the time it might fail, but I took a punt.
The weak point is here: you do not say where to save the newly created crontab file. So mine ended up in tmp I think. It’s probably still there, and I still have a bunch of updates to do.
Where should it be saved?
That’s very dangerous if you have custom .conf files. eg for ssh, ftp-d clients and so on… because -y overwrites old config files.
Pingback: Steve Miller’s Web Sites of Interest » links for 2007-05-16
In regards to overwritten conf files, just back them up so you can restore them if necesary.
Wouldn’t it be better to use anacron instead of cron?
What if the machine is off power when the cron job is programmed to be run?
fix this posting. this is as clear as mud!!!
RE:anacron
By default on Ubuntu systems, anacron is set up to automatically run cron jobs that don’t get executed on time.
At least, that’s what I think the settings in /etc/anacrontab mean. Check them yourself.
Post this only if I’m right:
If you are running GUI, you might want to disable the Automatic Updates under System -> Administration -> Software Sources -> Updates, so you aren’t doing the same job twice.
Here is a very similar procedure on the official Ubuntu website:
https://help.ubuntu.com/8.10/serverguide/C/automa…
To compensate aptitude overwriting config files sometimes I made a script that backs up all my custom configuration files, runs the aptitude command, then copies the config files back. I then set that script to run as a cron job. It's pretty simple, and ensures I don't lose any configuration files while allowing me to make changes to confs without then explicitly backing them up.
Thanks a lot for this article. Really help me.
Isn't there something built into apt-get or aptitude to run as a service?
Isn't there something built into apt-get or aptitude to run as a service?
From https://help.ubuntu.com/9.04/serverguide/C/automatic-updates.html
sudo apt-get install unattended-upgrades
Look the page for basic info