The yum command line tool is used to install and update software packages under RHEL / CentOS Linux server. I know how to apply updates using yum update command line, but I would like to use cron to update packages where appropriate manually. How do I configure yum to install software patches/updates automatically with cron?
You need to install yum-cron package. It provides files needed to run yum updates as a cron job. Install this package if you want auto yum updates nightly via cron.
Type the following yum command on:$ sudo yum install yum-cron
Turn on service using systemctl command on CentOS/RHEL 7.x:$ sudo systemctl enable yum-cron.service
$ sudo systemctl start yum-cron.service
$ sudo systemctl status yum-cron.service
If you are using CentOS/RHEL 6.x, run:$ sudo chkconfig yum-cron on
$ sudo service yum-cron start
yum-cron is an alternate interface to yum. Very convenient way to call yum from cron. It provides methods to keep repository metadata up to date, and to check for, download, and apply updates. Rather than accepting many different command line arguments, the different functions of yum-cron can be accessed through config files.
You need to edit /etc/yum/yum-cron.conf and /etc/yum/yum-cron-hourly.conf files using a text editor such as vi command:$ sudo vi /etc/yum/yum-cron.conf
Make sure updates should be applied when they are availableapply_updates = yes
You can set the address to send email messages from. Please note that ‘localhost’ will be replaced with the value of system_name.email_from = root@localhost
List of addresses to send messages to.email_to = your-it-support@some-domain-name
Name of the host to connect to to send email messages.email_host = localhost
If you do not want to update kernel package add the following on CentOS/RHEL 7.x:exclude=kernel*
For RHEL/CentOS 6.x add the following to exclude kernel package from updating:YUM_PARAMETER=kernel*
Save and close the file in vi/vim. You also need to update /etc/yum/yum-cron-hourly.conf file if you want to apply update hourly. Otherwise /etc/yum/yum-cron.conf will run on daily using the following cron job (us cat command:$ cat /etc/cron.daily/0yum-daily.cron
Sample outputs:
That is all. Now your system will update automatically everyday using yum-cron. See man page of yum-cron for more details:$ man yum-cron
Warning: The following method is outdated. Do not use it on RHEL/CentOS 6.x/7.x. I kept it below for historical reasons only when I used it on CentOS/RHEL version 4.x/5.x.
Let us see how to configure CentOS/RHEL for yum automatic update retrieval and installation of security packages. You can use yum-updatesd service provided with CentOS / RHEL servers. However, this service provides a few overheads. You can create daily or weekly updates with the following shell script. Create
A shell script that instructs yum to update any packages it finds via cron:
(Code listing -01: /etc/cron.daily/yumupdate.sh)
Where,
-d 0 : Sets the debugging level to 0 – turns up or down the amount of things that are printed. (range: 0 – 10).
Make sure you setup executable permission:# chmod +x /etc/cron.daily/yumupdate.sh
Article Number: 410
Posted: Wed, Oct 17, 2018 9:53 PM
Last Updated: Wed, Oct 17, 2018 9:53 PM
Online URL: http://kb.ictbanking.net/article.php?id=410