3

I'm trying to get last version of installed kernel package. The main difficulty is that in my case the versions may be installed in a wrong order, so I cannot simply use the --last argument from rpm.

I wanted to use the coreutils' sort command (coreutils-8.4-31.el6_5.1) which contains a --version-sort argument, but this does not return as expected:

$ rpm -q 'kernel' |sort --version-sort
kernel-2.6.32-431.5.1.el6.x86_64
kernel-2.6.32-431.11.2.el6.x86_64
kernel-2.6.32-431.17.1.el6.x86_64
kernel-2.6.32-431.el6.x86_64

rpm -q 'kernel' --last
kernel-2.6.32-431.17.1.el6.x86_64             mar. 13 mai 2014 09:48:44 CEST
kernel-2.6.32-431.11.2.el6.x86_64             jeu. 24 avril 2014 11:15:25 CEST
kernel-2.6.32-431.5.1.el6.x86_64              mer. 12 mars 2014 15:52:23 CET
kernel-2.6.32-431.el6.x86_64                  ven. 29 nov. 2013 17:48:19 CET

As you can see, the revision 431.e16 (the oldest) is sorted as the latest. A call to rpm -qi confirm that:

Release     : 431.17.1.el6                  Build Date: jeu. 08 mai 2014 02:48:49 CEST
Release     : 431.el6                       Build Date: ven. 22 nov. 2013 05:28:33 CET

Is this a known bug of sort? Is it already patched? Is there a simple workaround or another way to get the latest installed version?

1 Answer 1

6

You can do this by specifying a custom query format.

# rpm -q --qf="%{BUILDTIME} %{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" kernel

This will display the time the package was originally created (by Red Hat) as a UNIX timestamp followed by the package name.

To finish it off, all you need is...

# rpm -q --qf="%{BUILDTIME} %{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" kernel | \
  sort | tail -n 1 | cut -f 2 -d ' '
3
  • The problem is that the INSTALLTIME may false the result. In some specific cases, it occurs that an older version is installed after the newest but I want to get the most up to date installed version of the package. So it must be independant of the installation time.
    – aveuiller
    Jun 3, 2014 at 12:39
  • Hm, better use BUILDTIME instead. Jun 3, 2014 at 12:42
  • That's exactly what I was looking for, but it may be better to use a . instead of - between %{RELEASE} and %{ARCH} to retrieve the standard syntax.
    – aveuiller
    Jun 3, 2014 at 13:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .