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
HP-UX - Stunnel Configuration
Viewed 426 times since Fri, Sep 28, 2018
Extending Linux LVM partitions script
Viewed 461 times since Wed, Feb 6, 2019
Linux PAM configuration that allows or deny login via the sshd server
Viewed 421 times since Wed, Oct 3, 2018
SSH: Execute Remote Command or Script – Linux
Viewed 393 times since Mon, Feb 18, 2019
LVM: Extend SWAP size by growing existing Logical Volume
Viewed 655 times since Sat, Jun 2, 2018
RHCS6: Reduce a Global Filesystem 2 (GFS2)
Viewed 567 times since Sun, Jun 3, 2018
HowTo: Send Email from an SMTP Server using the Command Line
Viewed 417 times since Mon, Feb 18, 2019
CentOS / RHEL : Configure yum automatic updates with yum-cron service
Viewed 2084 times since Fri, Oct 26, 2018
Linux - How to unlock and reset user’s account
Viewed 500 times since Fri, Jun 8, 2018
SSL HowTo: Decode CSR
Viewed 462 times since Mon, Feb 18, 2019