In many docker container, le /boot is empty. Though, the vmlinuz is available in /var/lib/modules/<kver>/vmlinuz
In shell, I can do:
for kver in $(ls /lib/modules|sort -Vr)
do
test -f /lib/modules/$kver/vmlinuz && echo $kver && break
done
How can I do this un perl in a reliable way (I mean: using modules that are present in CentOS-6 to CentOS-8 or any other Linux distro.
I’ve seen that modules for kernel version comparison or version sorting, but none are available as distro package in all release of CentOS ranging from 6 to 8 included (8 is important as it s a clone of RHEL-8 and RHEL-8 is extremely stripped down distro regarding perl packages).
If I have those 2 versions: 4.18.0-144.el8.x86_64 4.18.0-80.7.1.el8_0.x86_64 I need to chose the -144 one.
2
Answers
The easiest way to do this would be to use the Sort::Versions module (which you’d need to install from CPAN).
Update: Your question includes this:
Of course, packages aren’t the only way to install CPAN modules. You could always use
cpan
orcpanm
. But if you really don’t want to install a module that way, then you could also cut and paste theversioncmp()
subroutine into your code. It’s only a few dozen lines of code.Is it cheating to use
ls
within perl?