I want to use crontab to run a script for yum updates. The problem is it seems it will run the script once, then yum is just stuck for a while (and can't be ran again). I get this error:

$ sudo yum update
Existing lock /var/run/yum.pid: another copy is running as pid 5248.
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: yum
Started:... 5 day(s) ago...
State: Sleeping, pid: 5248

This is what I place in crontab:

$ sudo crontab -e
0 4 * * *

This is what's in the script:

$ sudo vim /usr/local/bin/yum_updates.sh
yum makecache
yum -y update
yum -y upgrade

I considered yum-cron, but I've looked over the config file and it doesn't seem as customizable as crontab (i.e. I can't run security updates one day and full updates a different day), but correct me if I'm wrong, I haven't used yum-cron that much.

I would like to know how to stop this error, so I can run scripts using crontab without it holding the program hostage or getting the process stuck after only running once.


change your script to

#this line will kill that process is runing yum 
kill -9 `ps -aux | grep yum |tr -s " " : | cut -f2 -d : | head -1` 
yum makecache
kill -9 `ps -aux | grep yum |tr -s " " : | cut -f2 -d : | head -1`
yum -y update
yum -y upgrade
  • Much safer to just use pkill yum instead of that pipeline... If there are lock files, your code would not remove them (I'm not a yum user). Also, kill -9 is almost always overkill. – Kusalananda Jul 13 '18 at 9:27
  • pkill yum will not working. you can try @Kusalananda – omid abbasi Jul 13 '18 at 9:28
  • Well, pkill -f yum would match yum anywhere on the command line. – Kusalananda Jul 13 '18 at 9:28
  • pkill -f yum will not kill yum . i tried it now @Kusalananda – omid abbasi Jul 13 '18 at 9:31

Killing yum ins't what you want, I mean you will get package corruption at some time for sure. There is package like yum-cron that can solve your problem in proper manner. Install it, edit /etc/yum/yum-cron.conf according to your needs (install security only or all)

enable service and start it.

You will not longer need to worry about half done updates/upgrades or any other problems that killing might result in



There's no need to do your own crontab entry to run YUM periodically. YUM has a addon package called yum-cron. This tutorial, titled: How to enable automatic security updates on CentOS 7 with yum-cron, shows how to configure and operate it.

First make sure it's installed:

$ sudo yum -y install yum-cron

Then configure it:

$ cat /etc/yum/yum-cron.conf
apply_updates = yes

Enable & start the service: Once you've made the necessary changes, be sure that the service is enabled and running/restarted:

$ sudo systemctl enable --now yum-cron

What else?

Keep in mind that doing all your updates is just the tip of what yum-cron can do. You can also configure it to exclude specific packages that you'd prefer it not deal with:

exclude = kernel*


  • Yes, but yum-cron is not as customizable with the times, correct? I would like to run certain updates certain times of the month/week/day and certain updates at other times. Do you know why yum gets locked up with crontab? Is that a yum problem or do other programs that are ran in a script (automated with crontab) get stuck too? – user236643 Jul 14 '18 at 12:49
  • So run yum-cron but not in daemon mode. You can run it as an interactive program from Cron, just guard calling it by making sure it isn't already running. – slm Jul 14 '18 at 13:49

Great answers, but I found I could just make each type of yum update its own crontab entry like so:

$ sudo crontab -e

#Full system update midnight every Monday and Tuesday
0 0 * * 1,2 /usr/bin/yum -y update

10 0 * * 1,2 /usr/bin/yum -y upgrade

#Security updates everyday at 2AM
0 2 * * * /usr/bin/yum -y update --security

Takes more lines, but seems to work just fine. It needs to be noted that each entry should have a blank line below it, especially the last entry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy