AIX

check_uptime

Description:

Simple script to check the uptime of a Linux, Unix, or Solaris host. This check is informational only, it always returns ‘OK’

Sample use:
define service{
host_name SERVER
service_description Uptime
check_command check_uptime
}

Sample output:
System Uptime – up 9 days, 5 Hours, 02 Minutes

Current Version

1.02

Last Release Date

2009-11-12

Compatible With

  • Nagios 2.x
  • Nagios 3.x

Project Files
Project Notes
Reviews (4) Add a Review
Great, but...
by pelicanmedia, July 31, 2017

...incorrect results depending on time format... Using: struptime=`uptime | awk '{print $2,$3,$4,$5}'` if [[ $struptime == *day* ]]; then struptime1=${struptime%,} else struptime1=${struptime%, *} fi strdayshours=${struptime1%%:*}' hours ' strminutes=${struptime1##*:} strminutes1=${strminutes%%,*}' minutes' echo "System Uptime -" $strdayshours$strminutes1 exit 0 Machine up for 10 minutes: Command = uptime Result = 12:36:04 up 10 min, 1 user, load average: 0.00, 0.00, 0.00 Command = uptime | awk '{print $2,$3,$4,$5}' Result = up 10 min, 1 Command = /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_uptime Result = System Uptime - up 10 min hours up 10 min minutes Machine up for 2 hours: Command = uptime Result = 12:48:27 up 2:02, 2 users, load average: 0.12, 0.06, 0.06 Command = uptime | awk '{print $2,$3,$4,$5}' Result = up 2:02, 2 users, Command = /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_uptime Result = System Uptime - up 2 hours 02 minutes Arguments $2,$3,$4,$5 are different depending if the time is in HH:MM format it works (not sure on days yet as have rebooted my servers) but breaks if it contains 'min'. Guess it needs another if statement, but I am not knowledgable enough to work it out...



It works!
by ytaborda17, April 30, 2013

The output is like this: "System Uptime - up 16 Hours, 23, 2 users Minutes" so, I added this line: "strminutes1=${strminutes%%,*}' Minutes'" this way the output, comes this way "System Uptime - up 5 Hours, 36 Minutes" or "System Uptime - up 10 days, 10 Hours, 49 Minutes" Complete code: struptime=`uptime | awk '{print $2,$3,$4,$5}'` struptime1=${struptime%,} strdayshours=${struptime1%%:*}' Hours, ' strminutes=${struptime1##*:} strminutes1=${strminutes%%,*}' Minutes' echo "System Uptime -" $strdayshours$strminutes1 exit 0 Thanks a lot!



Works nice if uptime > 24 hours
by Iker Hoek, February 28, 2013

Works as expected when uptime is higher than a day. When it is not, the output looks like this: "System Uptime - up 11 Hours, 16, 2 users Minutes" I just put the line 7 inside an if that checks if there is an instance of "day" in the variable and formats accordingly: if [[ $struptime == *day* ]]; then struptime1=${struptime%,} else struptime1=${struptime%, *} fi I hope it helps =)



Works as expected
by linux_samurai, September 30, 2011

This checks does what is intended. A simple bash script that awk's the uptime with output being user-friendly. We have implemented this check on Red Hat & CentOS 5 servers.



Add a Review

You must be logged in to submit a review.

Thank you for your review!

Your review has been submitted and is pending approval.

Recommend

To:


From:


Thank you for your recommendation!

Your recommendation has been sent.

Project Stats
Rating
4.8 (4)
Favorites
1
Views
216,301