Search pacman for latest kernel in script

Hi there,
I have two strings, runnung kernel and installed kernel:

uname -r | cut -d- -f1,2,3


pacman -Q linux | cut -d’ ’ -f2 | sed -e ‘s/.([^.]*)$/-\1/’

I am seeking a way to get a similar string containing the latest kernel in the repo, but unfortunately none of my approaches succeed. If you have any idea I’d highly appreciate!

I do not understand the issue

[don@don-pc ~]$ uname -r | cut -d- -f1,2,3
[don@don-pc ~]$ 

even if that’s enough?

[don@don-pc ~]$ uname -a
Linux don-pc 5.0.4-zen1-1-zen #1 ZEN SMP PREEMPT Sat Mar 23 20:59:30 UTC 2019 x86_64 GNU/Linux
[don@don-pc ~]$ 

Ive no idea about sed commands but a simple
pacman -Si linux
shows latest kernel in repo.

1 Like

Thank you very much, @s7l!

pacman -Si linux | sed -n 3p | cut -d: -f2 | tr -d " " | sed -e ‘s/.([^.]*)$/-\1/’

gave me the output I need:

1 Like

Those output are supposed to match, looks like you may have had your /boot partition unmounted during a kernel upgrade.

I am surprised you can boot at all tbh.

1 Like

Question: could it have two kernels and start with the second one?

Glad that helped entropy, can i ask what you are doing, what sort of script your putting together?

1 Like

@Head_on_a_Stick: This is after kernel update not yet rebooted. uname -r output running kernel, pacman -Q linux installed kernel and pacman -Si linux latest kernel available.
@ector: No!
@s7l: I am sometimes lazy rebooting what can lead to something not working, like android usb tethering, CPU downvolting etc. So I setup script to show if I am running latest kernel installed and thought it would be nice if it would also show if there is an even newer kernel available, before I reboot. Will post here once I finished. Thanks again for your solution!

1 Like
#! /usr/bin/env zsh
installed_kernel=$(pacman -Q linux | cut -d' ' -f2 | sed -e 's/.\([^.]*\)$/-\1/')
running_kernel=$(uname -r | cut -d- -f1,2,3)
available_kernel=$(pacman -Si linux | sed -n 3p | cut -d: -f2 | tr -d " " | sed -e 's/.\([^.]*\)$/-\1/')

#echo -e "running:\t$running_kernel\ninstalled:\t$installed_kernel\navailable:\t$available_kernel\n"
#tabs 4

if [ "$installed_kernel" = "$running_kernel" ]
	echo -e "\e[32mKernel in sync!\t\e[1m$running_kernel\e[0m"
	if [ "$running_kernel" != "$available_kernel" ]
		echo -e "However, new kernel available:\t\e[33m\e[1m$available_kernel\e[0m"
	echo -e "\e[31mkernel out of sync!\e[0m"
	echo -e "running:\t\e[31m\e[1m$running_kernel\n\e[0minstalled:\t\e[32m\e[1m$installed_kernel\e[0m"
	if [ "$installed_kernel" != "$available_kernel" ]
		echo -e "available:\t\e[33m\e[1m$available_kernel\e[0m"
	read -k 1 "REPLY?Reboot new kernel now? (y/n)"
	if [[ "$REPLY" =~ ^[Yy]$ ]]
		exit 1
1 Like

thank @entr0py
my test

[don@don-pc ~]$ /home/don/Script/
kernel out of sync!
running:	5.0.4-zen1-1
installed:	4.8-14-1
available:	5.0.4-arch1-1
Reboot new kernel now? (y/n)n[don@don-pc ~]$ 
1 Like

Thank you @ector!
Looks pretty buggy, as my script can’t handle different kernels! Could you please post the output of:
uname -a && pacman -Q linux && pacman -Si linux

Ah yes, that would explain things :slight_smile:

Note that pacman -Si linux and pacman -Qi linux should always match:

It is not safely possible to update the package database and leave the packages un-upgraded, this is why ArchLabs’ update checker does it work in a chroot.

1 Like
[don@don-pc ~] 
[don@don-pc ~]$ uname -a && pacman -Q linux && pacman -Si linux
Linux don-pc 5.0.4-zen1-1-zen #1 ZEN SMP PREEMPT Sat Mar 23 20:59:30 UTC 2019 x86_64 GNU/Linux
[sudo] password di don: 
linux 4.8.14-1
Repository                : core
Nome                      : linux
Versione                  : 5.0.4.arch1-1
Descrizione               : The Linux kernel and modules
Architettura              : x86_64
URL                       :
Licenze                   : GPL2
Gruppi                    : base
Fornisce                  : Nessuno
Dipenda da                : coreutils  linux-firmware  kmod  mkinitcpio
Dipendenze opzionali      : crda: to set the correct wireless channels of your
Conflitti con             : Nessuno
Sostituisce               : Nessuno
Dimensione del download   : 70,66 MiB
Spazio richiesto          : 75,40 MiB
Pacchettizzatore          : Jan Alexander Steffens (heftig)
Data di creazione         : sab 23 mar 2019 21:57:31 CET
Convalidato da            : Somma MD5  Somma SHA-256  Firma

[don@don-pc ~]$ 

I have two kenels installed
this is correct

Hmm, I’m a bit confused. I guess you are running zen actual zen kernel, which you installed while 4.8.14-1 was actual?
Anyway, I have no clue how to adopt the script to this situation, as I have never used anything but stock stock kernels.

yes,booting the zen kernel, 4.18 is for emergencies, in case you don’t start zen when I update the kernel.