Skip to content

Instantly share code, notes, and snippets.

@eggbean
Last active June 6, 2023 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eggbean/0429a7bf4c2546085f2a5acd8c7a5421 to your computer and use it in GitHub Desktop.
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.
#!/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