0

How can I get a space-separated list of the packages with pending updates on CentOS7 in the format that is required for passing as an argument to the yum update-to command?

I want to update all the packages on my production server running CentOS7. Before I update them on production, I want to update them on staging and verify that the changes don't break our server's applications. After validation, we'll schedule a change ticket for production and run that same/vetted yum update-to command (as opposed to the potentially non-deterministic & non-idempotent yum update command) on production at a later date.

So I'm trying to [a] determine all the packages that have an update available for them on my server and [b] prepare a command using yum update-to that will list exactly the packages and their versions to be updated.

Here's an example of the yum update-to command's required syntax:

yum update-to dbus-1.10.24-13.el7_6 dbus-libs-1.10.24-13.el7_6 java-1.8.0-openjdk-1.8.0.242.b08-1.el7 java-1.8.0-openjdk-headless-1.8.0.242.b08-1.el7 tzdata-java-2019c-1.el7 unzip-6.0-21.el7

The problem is that yum update --assumeno and yum list updates both output the list of packages in a totally distinct format than what yum update-to expects.

Here's an example of the above commands' output related to the packages in the example above:

[root@cent7 ~]# yum update --assumeno | grep -E 'dbus|java|unzip'
---> Package dbus.x86_64 1:1.6.12-17.el7 will be updated
---> Package dbus.x86_64 1:1.10.24-13.el7_6 will be an update
---> Package dbus-libs.x86_64 1:1.6.12-17.el7 will be updated
---> Package dbus-libs.x86_64 1:1.10.24-13.el7_6 will be an update
---> Package java-1.8.0-openjdk.x86_64 1:1.8.0.181-3.b13.el7_5 will be updated
---> Package java-1.8.0-openjdk.x86_64 1:1.8.0.242.b08-1.el7 will be an update
--> Processing Dependency: gtk2(x86-64) for package: 1:java-1.8.0-openjdk-1.8.0.242.b08-1.el7.x86_64
---> Package java-1.8.0-openjdk-headless.x86_64 1:1.8.0.181-3.b13.el7_5 will be updated
---> Package java-1.8.0-openjdk-headless.x86_64 1:1.8.0.242.b08-1.el7 will be an update
--> Processing Dependency: pcsc-lite-libs(x86-64) for package: 1:java-1.8.0-openjdk-headless-1.8.0.242.b08-1.el7.x86_64
--> Processing Dependency: cups-libs(x86-64) for package: 1:java-1.8.0-openjdk-headless-1.8.0.242.b08-1.el7.x86_64
---> Package tzdata-java.noarch 0:2017b-1.el7 will be updated
---> Package tzdata-java.noarch 0:2019c-1.el7 will be an update
---> Package unzip.x86_64 0:6.0-16.el7 will be updated
---> Package unzip.x86_64 0:6.0-21.el7 will be an update
 dbus                     x86_64 1:1.10.24-13.el7_6              base     245 k
 dbus-libs                x86_64 1:1.10.24-13.el7_6              base     169 k
 java-1.8.0-openjdk       x86_64 1:1.8.0.242.b08-1.el7           base     293 k
 java-1.8.0-openjdk-headless
 tzdata-java              noarch 2019c-1.el7                     base     187 k
 unzip                    x86_64 6.0-21.el7                      base     171 k
[root@cent7 ~]# 
[root@cent7 ~]# yum list updates | grep -E 'dbus|java|unzip'
dbus.x86_64                           1:1.10.24-13.el7_6                base    
dbus-libs.x86_64                      1:1.10.24-13.el7_6                base    
java-1.8.0-openjdk.x86_64             1:1.8.0.242.b08-1.el7             base    
java-1.8.0-openjdk-headless.x86_64    1:1.8.0.242.b08-1.el7             base    
tzdata-java.noarch                    2019c-1.el7                       base    
unzip.x86_64                          6.0-21.el7                        base    
[root@cent7 ~]# 

How do I get translate the output of the packages and their versions from yum update --assumeno or yum list updates into a format that is accepted by yum update-to?

0

This solution with sed and awk works:

[root@cent7 ~]# pkgs=`yum -q list updates 2>&1 | tail -n+2 | awk '{print $1 "|" $2}' | sed 's/\.[^.]*|\(.*\:\)*/-/' | tr "\n" " "`
[root@cent7 ~]# echo "yum update-to $pkgs"
yum update-to dbus-1.10.24-13.el7_6 dbus-libs-1.10.24-13.el7_6 java-1.8.0-openjdk-1.8.0.242.b08-1.el7 java-1.8.0-openjdk-headless-1.8.0.242.b08-1.el7 tzdata-java-2019c-1.el7 unzip-6.0-21.el7 
[root@cent7 ~]# 

But I hope someone can come up with a better solution that's less of a hack. Ideally the solution would be one that tells yum to output the format in a more batch-friendly format.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.