You are not logged in.

#1 2013-11-27 13:54:27

BasioMeusPuga
Member
Registered: 2011-12-18
Posts: 19

Command to check if the system requires a reboot

Hey,

Pretty self explanatory. I just want to know if there's a command that checks if a reboot is needed.
I've Googled for this and the few results I've gotten are for Ubuntu/RHEL.

Thanks.

Offline

#2 2013-11-27 13:59:40

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Command to check if the system requires a reboot

Sometimes an update will tell you in pacman's output that you should reboot.
I think there already was a thread about this on the forums.

Reboot after kernel upgrade.

Offline

#3 2013-11-27 14:14:20

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Command to check if the system requires a reboot

Compare the running kernel version to the installed version, and display a message saying "REBOOT NOW" if they're different. This can be easily automated in a script.

Or just watch pacman's output and reboot when you see a kernel upgrade. :-)

Offline

#4 2013-11-27 14:17:18

BasioMeusPuga
Member
Registered: 2011-12-18
Posts: 19

Re: Command to check if the system requires a reboot

I grepped my pacman log and there's only 5 instances of the word "reboot" in the ~2 years this installation has lasted. As it is, this isn't suited for monitoring purposes.
Also, I checked the forums. Unless I'm missing something, the threads that talk about anything remotely similar are mostly to do with troubleshooting/"How often do you reboot?".

I think the question is still valid. Is there a command that checks to see if a reboot is required? To rephrase, does a kernel (module) upgrade touch a file/variable somewhere that can be checked?

Edit: Yeah. I thought about scripting this. Seemed a little excessive at the time though. I guess that's where I'll go. Thanks. smile

Last edited by BasioMeusPuga (2013-11-27 14:19:08)

Offline

#5 2013-11-27 14:22:22

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Command to check if the system requires a reboot

nvidia packages use https://projects.archlinux.org/svntogit … ges/nvidia

post_install() {
    EXTRAMODULES='extramodules-3.12-ARCH'
    depmod $(cat /usr/lib/modules/$EXTRAMODULES/version)
    echo 'In order to use nvidia module, reboot the system.'
}

Offline

#6 2013-11-27 14:28:31

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 12,327
Website

Re: Command to check if the system requires a reboot

There is no command that can tell you when you 'need' to reboot, you have to use common sense.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#7 2013-11-27 14:32:34

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Command to check if the system requires a reboot

My take on tomk's suggestion:

#!/usr/bin/bash

s1=$(pacman -Q linux | sed 's/linux //')
s2=$(uname -r | sed 's/-ARCH//')

if [ "$s1" == "$s2" ]; then
  echo OK
else
  echo REBOOT
fi

Offline

#8 2013-11-27 14:37:50

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,636
Website

Re: Command to check if the system requires a reboot

Whenever the nfs-utils package gets updated, on my configuration, I need to reboot the machine or else shares are not exported.  I have tried restarting the indiviual nfs services but only the reboot fixes it.  SO... you might wanna add nfs-utils to your list of "REBOOT" packages if this is true for you too.

A related thread: https://bbs.archlinux.org/viewtopic.php?id=173341


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#9 2013-11-27 14:40:24

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Command to check if the system requires a reboot

Thanks. For some reason I thought I was subscribed to this thread but I wasn't.

There's also e.g. https://bbs.archlinux.org/viewtopic.php?id=141095 dealing with the "do I really have to reboot after kernel upgrade?" question.

Offline

#10 2013-11-27 17:09:55

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Command to check if the system requires a reboot

karol wrote:

My take on tomk's suggestion:

#!/usr/bin/bash

s1=$(pacman -Q linux | sed 's/linux //')
s2=$(uname -r | sed 's/-ARCH//')

if [ "$s1" == "$s2" ]; then
  echo OK
else
  echo REBOOT
fi

Almost exactly what I use, except that you need to accommodate 3.x kernels e.g. 3.12 - in that case, s1 will be 3.12 but s2 will be 3.12.0.

Last edited by tomk (2013-11-27 17:10:13)

Offline

#11 2013-11-27 17:36:59

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,237
Website

Re: Command to check if the system requires a reboot

[[ $(pacman -Q linux | cut -d " " -f 2) > $(uname -r) ]] && echo reboot

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#12 2024-07-26 06:45:05

hongster
Member
Registered: 2009-02-27
Posts: 37
Website

Re: Command to check if the system requires a reboot

Trilby wrote:
[[ $(pacman -Q linux | cut -d " " -f 2) > $(uname -r) ]] && echo reboot

String comparison does not work well with version number. "6.10.1.arch1-1" is lesser than "6.9.10-arch1-1" due to comparison of 3rd character ("1" vs "9").

Offline

#13 2024-07-26 14:50:36

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 12,327
Website

Re: Command to check if the system requires a reboot

Perhaps 'vercmp $(pacman -Q linux | cut -d " " -f 2) $(uname -r)' then.

However, this topic is over a decade old. It's unlikely that OP is still looking for a solution.

Closing.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

Board footer

Powered by FluxBB