Build precise queries to find exactly what you need
Press ESC to close
Your review has been submitted and is pending approval.
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
Owner
Paul Basehore
Compatible With
...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...
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 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 =)
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.
You must be logged in to submit a review.
To:
From:
We’ve completely redesigned the world’s largest repository of Nagios plugins and monitoring tools. Join thousands of users sharing monitoring solutions for servers, applications, and everything in between.
Due to our redesign, all existing accounts require a password reset to access your account again.
Ready to explore 6,100+ projects and contribute to the community?
Reset Password Create Account
Happy Monitoring!