From 77563481b1bbabb9f279fbe7c9f2597c2d5de1df Mon Sep 17 00:00:00 2001 From: Thorsten Spille Date: Thu, 8 Jul 2021 19:41:44 +0200 Subject: [PATCH] Create check_running_kernel --- running-kernel/check_running_kernel | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 running-kernel/check_running_kernel diff --git a/running-kernel/check_running_kernel b/running-kernel/check_running_kernel new file mode 100644 index 0000000..77d6b46 --- /dev/null +++ b/running-kernel/check_running_kernel @@ -0,0 +1,43 @@ +#!/bin/bash + +# check_running_kernel +# This plugin checks if the latest installed kernel is runnning or if the system needs to be rebooted + +# Author: (C)2021 Thorsten Spille + +# MIT License +# +# Copyright (c) 2021 Bash Club +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +uname=$(uname -r) +major_version=${uname:0:3} +if [[ "$uname" == *"-pve" ]]; then + filter=pve-kernel-$major_version +else + filter=linux-image-$major_version +fi +latest_kernel=$(dpkg --get-selections | grep $filter | tail -1 | cut -f1 | cut -d'-' -f3-) +if [[ "$latest_kernel" == "$uname" ]]; then + echo -e "0 \"Running Kernel\" version_ok=0;1;|running_kernel=$uname;;|latest_installed_kernel=$latest_kernel;; Currently running Kernel up-to-date - OK" +else + echo -e "1 \"Running Kernel\" version_ok=1;1;|running_kernel=$uname;;|latest_installed_kernel=$latest_kernel;; Newer Kernel version installed. Please reboot machine! - WARN" +fi