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
stunnel Securing telnet connections with stunnel
Viewed 1715 times since Sun, Dec 6, 2020
List of 10 Must Know Oracle Database Parameters for Database Administrator
Viewed 131268 times since Thu, Jun 21, 2018
HowTo: Kill TCP Connections in CLOSE_WAIT State
Viewed 16306 times since Thu, Feb 14, 2019
10 Linux rsync Examples to Exclude Files/Directories
Viewed 11161 times since Wed, Oct 31, 2018
Top 25 Best Linux Performance Monitoring and Debugging Tools
Viewed 7307 times since Sun, Sep 30, 2018
LVM: Reduce SWAP size by removing a Logical Volume
Viewed 2249 times since Sat, Jun 2, 2018
RHEL: Crash kernel dumps configuration and analysis on RHEL 7
Viewed 7390 times since Sat, Jun 2, 2018
Using grep to find string in files
Viewed 2455 times since Fri, May 15, 2020
HOWTO: Use SSL/port 465 in smarthost stunnel
Viewed 4064 times since Fri, Sep 28, 2018
how to list all hard disks in linux from command line
Viewed 3876 times since Mon, Jan 28, 2019