From 875a961eba153b3cc768fbd2769d6220d67859ca Mon Sep 17 00:00:00 2001 From: Salt Date: Wed, 18 Aug 2021 22:57:41 -0500 Subject: [PATCH] Add a reboot-required check --- check_reboot_required | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 check_reboot_required diff --git a/check_reboot_required b/check_reboot_required new file mode 100755 index 0000000..deee075 --- /dev/null +++ b/check_reboot_required @@ -0,0 +1,28 @@ +#! /bin/bash +# +# check_reboot_required.sh +# Copyright (C) 2021 Vintage Salt +# +# Distributed under terms of the MIT license. +# + +rr="/var/run/reboot-required" +# 604800 - 1 week in seconds +threshold="604800" +if [ -f "$rr" ]; then + # We have a pending reboot; alert in different states depending on its age + lastmod=$(date +%s -r "$rr") + now=$(date +%s) + if (( now - lastmod > threshold )); then + echo "CRITICAL - Pending reboot older than $threshold seconds: $(cat rr)" + exit 2 + else + echo "WARNING - Pending reboot: $(cat rr)" + exit 1 + fi +else + # We have no pending reboots + echo "OK - No pending reboots" + exit 0 +fi +