Amazon Linux - Check If Need Reboot

Below is a BASH script you can use to tell you whether you need to reboot your instance in order to use a later kernel.

#!/bin/bash

LAST_KERNEL=$(rpm -q --last kernel | perl -pe 's/^kernel-(\S+).*/$1/' | head -1); 
CURRENT_KERNEL=$(uname -r); 

if [ $LAST_KERNEL != $CURRENT_KERNEL ]; then 
    echo 'reboot'; 
else 
    echo 'no'; 
fi

Author

Programster

Stuart is a software developer with a passion for Linux and open source projects.

comments powered by Disqus
We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites. More info.