One of the very annoying things about having multiple Linux systems (or virtual machines) in the house is that you constantly need to keep them patched and updated. Sure, they are not as vulnerable as some Windows systems but it is still good practice to keep your systems nicely patched. So instead of doing sudo apt-get upgrade every time (or worse , getting a popup from the update manager while you are just in the middle of watching your favorite Youtube video about bunnies ) .. lets schedule this.
Scheduling things is not bad , but you have to be careful just WHAT you want those systems to do. You don’t want to wake up one morning and see that your LTS (long term support) workstation has just done a make-over and rolled onto the cutting edge version of the new release of your operating system. So kernel and distro upgrades should not be a part of your schedule.
The command we choose to use is Aptitude. With the following string you can do an update and upgrade on the same line.
/usr/bin/aptitude -y update && /usr/bin/aptitude -y safe-upgrade
So what does it do ?
“-y” makes sure that you don’t have to type YES at the end of the command.
” safe-upgrade” means that kernell or distro upgrades are a “nono”
“&&” links the commands together.
How to schedule it.
Simple. Log in as a user with root access and type “crontab -e”
next ad the following line to your cron
0 1 * * * /usr/bin/aptitude -y update && /usr/bin/aptitude -y safe-upgrade
Thats it. Now the the upgrade is executed every single night at 1 am.
source. Kevin van Zonnevelds blog.