[Xymon] Xymon script question

Jaap Winius jwinius at umrk.nl
Wed Jul 5 15:51:59 CEST 2017


Quoting Scot Kreienkamp <Scot.Kreienkamp at la-z-boy.com>:

Hi Scot,

Thanks for your reply, I'll try it out in a bit. In the mean time,  
here's my script:

==========================
#!/bin/bash

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

COLUMN=Reboot	# Name of the column
COLOR=green	# By default, everything is OK
MSG="Reboot required"

RUN=$(uname -r |awk -F - '{print $1}')	# Version of the running kernel
IRF=$(find /boot -type f -name "initrd.img-$RUN-*") # Find matching  
init.rd file
FMD=$(stat -c %Y $IRF)	# Modify date of init.rd file in seconds since 1970
UPT=$(cat /proc/uptime |awk -F \. '{print $1}')	# Seconds of uptime,  
rounded down
EPC=$(date +%s)		# Current epoch (seconds since 1970)
DIF=$(($EPC-$FMD))	# Age of init.rd file in seconds

if [ $DIF -gt $UPT ]
then
	MSG="${MSG}:

	No. Already running the latest version of Linux kernel $RUN.
	"
else
	COLOR=yellow

	LFT=$(stat -c %y $IRF |awk -F \. '{print $1}') # Last modified time
	LBT=$(who -b |awk '{print $3" "$4}') # Last boot time

	MSG="${MSG}:

	Yes. A new version of Linux kernel $RUN was installed on $LFT after  
the last reboot on $LBT.
	"
fi

# Tell Xymon about it
$XYMON $XYMSRV "status $MACHINE.$COLUMN $COLOR `date`

${MSG}
"

exit 0

==========================

I have the unattended-upgrades package installed on all of the  
clients, which are only set to notify me if an error occurs, so this  
way I'll know when it's time to reboot any of them.

Is there a Xymon repository somewhere for scripts like this?

Cheers,

Jaap



More information about the Xymon mailing list