[CentOS] one-shot yum command to match rpms between systems?

Matthew Miller mattdm at mattdm.org
Wed May 18 17:32:36 UTC 2016


On Wed, May 18, 2016 at 12:54:51AM -0600, Frank Cox wrote:
> Given a list of rpms on one system (rpm -qa > list.txt), is there a
> one-shot command that I can run on another system to remove all of
> the rpms not listed and add any that are on the list and not present
> on the second system?

I think you can pull this off with `yum shell`. First, though, don't do
`rpm -qa` as your list — do `rpm -qa --qf '%{name}.%{arch}\n'|sort` instead.
That way, version numbers won't complicate things.

And then, on the second system (the one you want to change), try this
crazy oneliner:

( rpm -qa --qf '%{name}.%{arch}\n' | sort | diff --old-line-format='install %L' --new-line-format='remove %L' -unchanged-line-format='' list.txt - ; echo run ) | yum shell

It's not really as bad as it looks — the diff formatting is just
verbose. The first command just gets the package list from the current
system; then we sort it, and then get the difference in a formatted as
a list of "install" and "remove" commands. Then add "run" to the end,
and pipe all of that to yum shell.

This is totally untested but I'll give it good odds of working. :)





-- 
Matthew Miller
<mattdm at fedoraproject.org>
Fedora Project Leader



More information about the CentOS mailing list