Last active
March 22, 2024 08:29
-
-
Save jvacek/18aaf9858d8ab8016297bee5e71f59ef to your computer and use it in GitHub Desktop.
Check whether linux server needs reboot and return for how long has the reboot been necessary in PRTG's format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#You can install and also update this script by running the follwoing command | |
# sudo curl https://gist.githubusercontent.com/jvacek/18aaf9858d8ab8016297bee5e71f59ef/raw/checkreboot.sh -L --create-dirs -o /var/prtg/scripts/checkreboot.sh; sudo chmod a+rx -R /var/prtg/ | |
#Create a new sensor for your machine, select SSH script, and select checkreboot.sh from the script dropdown. | |
#The value returned is in seconds. 0 seconds means no file is present. | |
#The sensor will be set to warning when the file is present. | |
#If you want the sensor to go down when a reboot has been required for more than 24h, set the upper error limit of the valu channel on the sensor to 86400. | |
#This is handy in case you have unattended-upgrades configured with reboots and want to make sure that updates apply as they should. | |
if [ -f /var/run/reboot-required ]; then | |
age=$(( $(date +%s) - $(date -r /var/run/reboot-required +%s) )) | |
echo "1:$age:Restart Required" | |
else | |
echo "0:0:No restart required" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment