From ae846418e2aaf3a36c86adc83761855a399813a0 Mon Sep 17 00:00:00 2001 From: Dallas Date: Wed, 9 May 2018 11:07:31 -0500 Subject: [PATCH] Create check_pf_uptime --- check_pf_uptime | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 check_pf_uptime diff --git a/check_pf_uptime b/check_pf_uptime new file mode 100644 index 0000000..3fedb95 --- /dev/null +++ b/check_pf_uptime @@ -0,0 +1,42 @@ +#!/bin/sh +# +# Dallas Haselhorst 9May2018 +# +# This is a modified version of what I found on Nagios Exchange. +# I freely admit I did not write the lines other than the final +# few of this script. +# + +UPTIME_REPORT=`uptime | tr -d ","` + +if echo $UPTIME_REPORT | grep -i day > /dev/null ; then + +if echo $UPTIME_REPORT | grep -i "min" > /dev/null ; then + +DAYS=`echo $UPTIME_REPORT | awk '{ print $3 }'` +MINUTES=`echo $UPTIME_REPORT | awk '{ print $5}'` + +else +DAYS=`echo $UPTIME_REPORT | awk '{ print $3 }'` +HOURS=`echo $UPTIME_REPORT | awk '{ print $5}' | cut -f1 -d":"` +MINUTES=`echo $UPTIME_REPORT | awk '{ print $5}' | cut -f2 -d":"` +fi + +elif #in AIX 5:00 will show up as 5 hours, and in Solaris 2.6 as 5 hr(s) +echo $UPTIME_REPORT | egrep -e "hour|hr\(s\)" > /dev/null ; then +HOURS=`echo $UPTIME_REPORT | awk '{ print $3}'` +else +echo $UPTIME_REPORT | awk '{ print $3}' | grep ":" > /dev/null && \ +HOURS=`echo $UPTIME_REPORT | awk '{ print $3}' | cut -f1 -d":"` +MINUTES=`echo $UPTIME_REPORT | awk '{ print $3}' | cut -f2 -d":"` +fi + +UPTIME_MSG="${DAYS:+$DAYS Days,} ${HOURS:+$HOURS Hours,} $MINUTES Minutes" + +if [ -z $DAYS ];then + echo WARNING - $UPTIME_MSG + exit 1 +else + echo OK - $UPTIME_MSG + exit 0 +fi