Automatic YUM Updates with Yum-cron

This post will guide you how to use yum-cron to update system under CentOS/RHEL Linux. How do I configure yum automatic updates with yum-cron tool in Linux. How to set yum updates with yum-cron.

What is Yum-cron?

 

The yum-cron is an optional package starting from RHEL 6/CentOS 6 and it is a yum plugin.
yum-cron is a simple way to call yum commands from cron. It provides configuration to keep repository metadata up to date, and to check for, download, and apply updates.

Install yum-cron


If you want to setup automatic yum updates with yum-cron, you need to install the yum-cron package firstly. Type the following command:

# yum install yum-cron

Outputs:

[root@devops ~]# yum install yum-cron
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: mirrors.huaweicloud.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package yum-cron.noarch 0:3.4.3-158.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
yum-cron noarch 3.4.3-158.el7.centos base 63 k

Transaction Summary
================================================================================
Install 1 Package

Total download size: 63 k
Installed size: 51 k
Is this ok [y/d/N]: y
Downloading packages:
yum-cron-3.4.3-158.el7.centos.noarch.rpm | 63 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : yum-cron-3.4.3-158.el7.centos.noarch 1/1
Verifying : yum-cron-3.4.3-158.el7.centos.noarch 1/1

Installed:
yum-cron.noarch 0:3.4.3-158.el7.centos

Complete!

Start Yum-cron Service


After installed yum-cron package, you need to start the yum-cron service.

For CentOS 7/RHEL 7 Linux:

# systemctl start yum-cron.service

Outputs:

[root@devops ~]# systemctl start yum-cron
[root@devops ~]# systemctl status yum-cron
yum-cron.service - Run automatic yum updates as a cron job
Loaded: loaded (/usr/lib/systemd/system/yum-cron.service; enabled; vendor preset: disabled)
Active: active (exited) since Sun 2018-09-16 11:14:36 EDT; 2s ago
Process: 3579 ExecStart=/bin/touch /var/lock/subsys/yum-cron (code=exited, status=0/SUCCESS)
Main PID: 3579 (code=exited, status=0/SUCCESS)

Sep 16 11:14:36 devops systemd[1]: Starting Run automatic yum updates as a .....
Sep 16 11:14:36 devops systemd[1]: Started Run automatic yum updates as a c...b.
Hint: Some lines were ellipsized, use -l to show in full.

For CentOS 6/RHEL 6 Linux:

Type the following command:

# service yum-cron start

Configure Yum-cron


You need to edit the configuration file of yum-cron, and it is located in /etc/yum/yum-cron.conf.

For CentOS 6/RHEL 6 Linux:

 

Adding the below line into the file:

MAILTO=osetc@gmail.com
YUM_PARAMETER=kernel* http*

Note: The YUM_PARAMETER variable is used to exclude packages using yum-cron to update the system. So it won’t update the kernel and http packages.

For CentOS 7/RHEL 7 Linux:

Adding the below line into the file:
MAILTO=osetc@gmail.com
exclude=kernel* http*

Then save and close the file.

You still need to restart the yum-cron service.

Type the following command:

# systemctl restart yum-cron

Or

# service yum-cron restart

By default, the yum-cron tool will be run daily based on the yum-daily.cron job. Let’s see this cron job.

[root@devops ~]# cat /etc/cron.daily/0yum-daily.cron
#!/bin/bash
# Only run if this flag is set. The flag is created by the yum-cron init
# script when the service is started -- this allows one to use chkconfig and
# the standard "service stop|start" commands to enable or disable yum-cron.
if [[ ! -f /var/lock/subsys/yum-cron ]]; then
exit 0
fi
# Action!
exec /usr/sbin/yum-cron

If you want to get more information about the yum-cron, just see the man page of yum-cron.

# man yum-cron
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
OpenSSL: Check SSL Certificate Expiration Date and More
Viewed 6163 times since Mon, Feb 18, 2019
RHEL7: How to get started with Firewalld.
Viewed 11626 times since Wed, May 22, 2019
An easier way to manage disk decryption at boot with Red Hat Enterprise Linux 7.5 using NBDE
Viewed 6867 times since Mon, Aug 6, 2018
linux ssh How to Hide the OpenSSH Version Details when Telnet to Port 22
Viewed 3716 times since Wed, Apr 22, 2020
LVM: Reduce SWAP size by removing a Logical Volume
Viewed 1746 times since Sat, Jun 2, 2018
ZFS: Verify/change properties of a zfs filesystem
Viewed 2280 times since Sun, Jun 3, 2018
How to maximise SSD performance with Linux
Viewed 8339 times since Fri, May 15, 2020
LVM: Extend SWAP size by growing existing Logical Volume
Viewed 2219 times since Sat, Jun 2, 2018
Using renice and taskset to manage process priority and CPU affinity with Linux OEL 6.4
Viewed 3282 times since Mon, Feb 17, 2020
LVM: Extend an existing Volume Group by adding a new disk
Viewed 1777 times since Sat, Jun 2, 2018