The yum command line tool is used to install and update software packages under RHEL / CentOS Linux server. I know how to apply updates using yum update command line, but I’d like to use cron to manually update packages where appropriate. How do I configure yum to install software patches / updates automatically with cron?
You can use yum-updatesd service provided with CentOS / RHEL servers. However, this service provides a few overheads. You can create daily or weekly updates with the following shell script. Create
- /etc/cron.daily/yumupdate.sh to apply updates one a day.
- /etc/cron.weekly/yumupdate.sh to apply updates once a week.
Sample shell script to update system
A shell script that instructs yum to update any packages it finds via cron:
#!/bin/bash YUM=/usr/bin/yum $YUM -y -R 120 -d 0 -e 0 update yum $YUM -y -R 10 -e 0 -d 0 update
(Code listing -01: /etc/cron.daily/yumupdate.sh)
- First command will update yum itself and next will apply system updates.
- -R 120 : Sets the maximum amount of time yum will wait before performing a command
- -e 0 : Sets the error level to 0 (range 0 – 10). 0 means print only critical errors about which you must be told.
- -d 0 : Sets the debugging level to 0 – turns up or down the amount of things that are printed. (range: 0 – 10).
- -y : Assume yes; assume that the answer to any question which would be asked is yes.
Make sure you setup executable permission:
# chmod +x /etc/cron.daily/yumupdate.sh