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

Wed May 18 18:26:38 UTC 2016
Johnny Hughes <johnny at centos.org>

On 05/18/2016 12:32 PM, Matthew Miller wrote:
> 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.

Right .. if you are not at the same update levels then name.arch is
better than full versions.

> 
> 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.




-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.centos.org/pipermail/centos/attachments/20160518/b62cfdec/attachment-0005.sig>