In Debian-based script: how to determine if kernel changed and needs reboot?

Solution 1:

What about checking the return code? needrestart -k -p > /dev/null; echo $? gives 0 for an up-to-date kernel, and 2 if the running kernel is not the expected one.