Build precise queries to find exactly what you need
Press ESC to close
…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…
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!