There are a number of strategies to replace Ubuntu. These strategies embrace bundle updates through the desktop, the unattended improve script, and good outdated Apt. Because the title suggests, this submit explores the final possibility utilizing Cron.
Utilizing the Apt command through Cron is especially supposed in case you have put in a cut-down, customised or server model of Ubuntu. Conversely, Desktop customers utilizing the total set up don’t want to fret because the GUI robotically handles updates.
You need to use the unattended improve script if you wish to write the small print and adjustments to the log information and ship a mail report back to a system admin consumer. Nonetheless, this may be scripted utilizing Bash if you want.
The unattended-upgrades script in Ubuntu is helpful once you need to:
- Do a dry run of an improve with out really putting in something.
- Deal with safety and non-security updates individually.
Due to this fact, this submit is especially supposed for Ubuntu server customers with a light-weight set up. Thus utilizing Apt and Cron can be an ideal match and a no-frills strategy.
As a matter of warning – upgrades can doubtlessly break issues—equally; it’s safer to be up-to-date.
Let’s get began!
First, open Cron utilizing the next command:
Word that you could run this command utilizing sudo. Alternatively, you could be logged in as root.
Subsequent, add the next strains utilizing your favorite textual content editor and save:
0 17 * * 7 /usr/bin/apt replace
0 18 * * 7 /usr/bin/apt improve -q -y
0 19 * * 7 /usr/bin/apt autoclean
The Apt replace command solely will get the details about the most recent model of packages out there in your system. Whereas the Apt improve command on Ubuntu downloads and upgrades the bundle to the brand new model.
Autoclean clears the native repository of retrieved bundle information. However it solely removes information that may now not be downloaded and are successfully ineffective.
You may set your Cron to run the Ubuntu APT updates anytime. The instance above runs the improve on Sundays beginning at 17:00, then at 18:00 and eventually at 19:00.
Utilizing Ansible?
Ansible permits for straightforward automation. For instance, you’ll be able to add the next to your playbook to replace Ubuntu utilizing Apt and Cron:
duties:
#
# Add replace cron
#
- identify: Replace
change into: sure
become_method: sudo
cron:
identify: "replace"
consumer: "root"
weekday: "7"
minute: "0"
hour: "19"
job: "/usr/bin/apt replace -q -y"
state: current
#
# Add improve cron
#
- identify: Improve
change into: sure
become_method: sudo
cron:
identify: "improve"
consumer: "root"
weekday: "7"
minute: "0"
hour: "20"
job: "/usr/bin/apt improve -q -y"
state: current
#
# Add autoclean cron
#
- identify: Autoclean
change into: sure
become_method: sudo
cron:
identify: "autoclean"
consumer: "root"
weekday: "7"
minute: "0"
hour: "23"
job: "/usr/bin/apt autoclean"
state: current
Wrapping Up
You’ve got realized the variations between Apt updates utilizing Cron, the desktop GUI replace methodology, and Ubuntu’s unattended-upgrades script. As well as, you realized how one can replace, improve and auto-clean your Apt cache utilizing Cron in Ubuntu.