≡ Menu

How to automatically run yum update using cron?

The question – I want to run a yum update automatically every day. How do I do this using cron?

Cron provides a way to do this very easily. Cron jobs can run daily, hourly, weekly and monthly.

There are directories in which you put the program or shell script that you want to run at a particular interval and cron will automatically run them.

The directories are as under:

[root@server ~]# ls /etc/cron.
cron.d/       cron.deny     cron.monthly/
cron.daily/   cron.hourly/  cron.weekly/

The above directories are automatically scanned and the programs and scripts in them are run at the interval denoted by the directory name.

So, to run yum update every day, you create a script and put it in the cron.daily directory and it will automatically run every day!

Create a script called update.sh that says the following:

#!/bin/bash
/usr/bin/yum -y update

The -y argument to yum will automatically say yes to all questions asked such as do you want to install this package.

Now copy the script to the following directory:

/etc/cron.daily/

After copying the file, run the following command:

cd /etc/cron.daily/
chmod a+x update.sh

This will allow every one to execute the script.

That’s it! Now yum update will run automatically every day!

{ 0 comments… add one }

Leave a Comment