I’ve made this script to monitor out all my server if got any kernel update on my CentOS box.

It’s pretty easy to use, save the script, chmod the file and add to crontab (I set Cronjob to 24 hours)

#!/bin/bash
# CentOS x64 Kernel Checker Script
# Created By Mohamad Zulfahmy
# https://blog.zulfahmy.net/blog/centos-x64-kernel-checker-script
# Usage : 
# chmod +x kernel-checker.sh
# add script to crontab

set -x

NOTIFY_EMAIL="[email protected]"
HOSTNAME=`hostname`
IPADDR=`ifconfig|grep inet|grep inet6 -v|awk '{print $2}'|cut -d':' -f 2|head -1`

current_kernel=`uname -r | awk {'gsub(".x86_64", ""); print'}`

function kernel_update_check() {
        latest_kernel=`yum -q check-update |grep kernel| awk {'print $2;exit;'}`
        if [ $latest_kernel == $current_kernel ] ; then
                echo "Kernel already on latest version"
        else
                echo -e "Got kernel update on $HOSTNAME n Server IP : $IPADDR n Current Kernel : $current_kernel n Latest Kernel : $latest_kernel" | 
                mail -s "KERNEL UPDATE: $HOSTNAME" $NOTIFY_EMAIL
        fi

}

kernel_update_check