Skip to main content
Question

Uptime +7 days Smart Group - need help with extension attribute?

  • June 4, 2018
  • 2 replies
  • 39 views

Forum|alt.badge.img+3

Hi, forgive me, super new to this. I would like to create a smart group with machines that have not been rebooted in more than 7 days. I thought I had the Extension Attributes correct as well as the settings for the smart group, see attached images. However, the smart group is showing a bunch of computers that have definitely been restarted in the previous 7 days.
See below for my settings and script:


Can anyone tell me what I'm doing wrong?
Thanks!!

2 replies

mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • June 4, 2018

I would consider doing some searches here for EAs related to getting the uptime of machines. There are many different approaches. It's possible the way your script is working is creating false positives. I'm not able to test it out right now, but I can take a look at it later to see. My guess is a different approach might give you better results.

Here's an example of getting the number of days uptime using sysctl, current unix time, and some math

#!/bin/bash

echo "<result>$(expr $(expr $(date +"%s") - $(sysctl kern.boottime | awk -F'[= |,]' '{print $6}')) / 60 / 60 / 24)</result>"

Forum|alt.badge.img+18
  • Contributor
  • June 4, 2018

Here's my EA for uptime (I round to 1 day if it's been up less than that). Your IF statement looks whack, to use a technical term, I don't know what it's doing.

I'd probably write this differently nowadays, but it works.

#!/bin/bash

uptimeRes=$(uptime)
if [ "$(echo $uptimeRes | grep day)" ]; then
    uptimeDays=$(echo $uptimeRes | awk '{print $3}')
else
    uptimeDays=1
fi
echo "<result>$uptimeDays</result>"