-
Notifications
You must be signed in to change notification settings - Fork 4
/
check_kernel.sh
executable file
·63 lines (53 loc) · 1.65 KB
/
check_kernel.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
#
# Copyright 2009-2017 Martin Scharm
#
# This file is part of bf-monitoring.
# <https://binfalse.de/software/nagios/>
# <https://github.com/binfalse/monitoring>
#
# bf-monitoring is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# bf-monitoring is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# bf-monitoring If not, see <http://www.gnu.org/licenses/>.
#
###################################
#
# Check if the system is running the latest kernel
# or if a reboot is necessary
#
# by Martin Scharm <https://binfalse.de/contact>
#
#
###################################
source /usr/lib/nagios/plugins/utils.sh
current_kernel=$(uname -r)
latest_kernel=$(find /boot/ -name vmlinuz-* | sort -V | tail -1 | sed 's/.*vmlinuz-//')
# no uname?
if [ -z "$current_kernel" ]
then
echo "uname returns empty string?"
exit ${STATE_CRITICAL}
fi
# no /boot/vmlinuz-* ?
if [ -z "$latest_kernel" ]
then
echo "no /boot/vmlinuz-* found.."
exit ${STATE_CRITICAL}
fi
# compare the strings
if [ "$current_kernel" = "$latest_kernel" ]
then
echo "running kernel is $current_kernel"
exit ${STATE_OK}
else
echo "your kernel $current_kernel is outdated, please boot into $latest_kernel"
exit ${STATE_WARNING}
fi