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
RHEL: Displaying/setting kernel parameters - ’sysctl’
Viewed 996 times since Sat, Jun 2, 2018
Configuring VLAN interfaces in Linux
Viewed 1253 times since Mon, May 21, 2018
Do you Know These 5 Use of V$session View ?
Viewed 5196 times since Thu, Jun 21, 2018
LVM: Reduce an existing Logical Volume / Filesystem
Viewed 643 times since Sat, Jun 2, 2018
Fałszujemy rozpoznania skanerów #1
Viewed 1004 times since Mon, May 21, 2018
10 Linux cryptsetup Examples for LUKS Key Management (How to Add, Remove, Change, Reset LUKS encryption Key)
Viewed 877 times since Tue, Jul 31, 2018
Installing and Configuring an OCFS2 Clustered File System
Viewed 904 times since Sat, Jun 2, 2018
ZFS: Remove an existing zfs filesystem
Viewed 600 times since Sun, Jun 3, 2018
Tropienie pożeracza dysku
Viewed 835 times since Thu, May 24, 2018
sed Delete / Remove ^M Carriage Return (Line Feed / CRLF) on Linux or Unix
Viewed 527 times since Thu, Feb 7, 2019