Build precise queries to find exactly what you need
Press ESC to close
Nagios World Conference 2026: Sept. 14-17 in St. Paul, MN | Learn More
Thank you for this !!
I have been hunting and testing for MONTHS to find a check_uptime script that works correctly. This is the only one that does with the different results (depending on time up) from ‘uptime’. i.e Minutes, Hours & Minutes, Days & Minutes, Day & Hours & Minutes.
I have made a few adjustments to mine as I have no need for warnings, just for monitoring:
========== #!/bin/sh
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”
echo System Uptime – $UPTIME_MSG ==========
I now have this running on CentOS, Ubuntu and Raspberry Pi servers, all running perfectly!
System Uptime – 0 Minutes System Uptime – 4 Hours, 19 Minutes System Uptime – 2 Days, 8 Hours, 54 Minutes