Posted on 06-04-2018 11:39 AM
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!!
Posted on 06-04-2018 12:07 PM
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>"
Posted on 06-04-2018 12:12 PM
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>"