Last active
June 6, 2023 05:13
-
-
Save eggbean/0429a7bf4c2546085f2a5acd8c7a5421 to your computer and use it in GitHub Desktop.
Bash snippet to determine if the kernel has been updated, requiring a reboot. Tested on Debian and RHEL-based systems. If you put it in your .bashrc, surround it with (parentheses) so that it runs in a subshell, or execute it as a separate script, as otherwise it would change your nullglob shell option and current directory if sourced.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cd /boot || exit 1 | |
shopt -s nullglob ; for file in config-* ; do kernels+=( "${file#config-}" ) ; done | |
newest="$(printf '%s\n' "${kernels[@]}" | sort -V -t - -k 1,2 | tail -n1)" | |
current="$(uname -r)" | |
[[ $current != $newest ]] && echo "Reboot needed for new kernel" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment