Hey everyone. I deployed a policy that runs a script which notifies users that they need to reboot their Macs. The policy is scoped to a Smart Group that contains users whose Macs have been up for 10 days or more. The issue I'm running into is that after the users reboot, they're seeing the notification again. My guess is that an inventory update isn't happening quickly enough after the reboot to remove them from the Smart Group. Can anyone help me configure this properly? Happy to provide any other details. Thanks in advance!
Solved
Reboot Notifications
Best answer by oluna777
As far as I understand, it seems that the smart group is using an extension attribute that reads the last time the computer restarted. Then, the extension attribute gets the most up-to-date data only after the inventory is posted to Jamf. If this is the case, then your policy is behaving like that because the the inventory that updates the extension attribute with the latest reboot time is not being posted BEFORE the next time the reboot policy runs.
As a personal preference, when I script I prefer to do validations on real time before assuming that the extension attribute is accurate.
This is what I would add to your script:
#!/bin/sh
# SOME VARIABLES WE NEED TO VALIDATE. YOU CAN USE HRS TO VALIDATE THE SCENARIO IN WHICH THE COMPUTER HAS BEEN UP FOR SOME HOURS. I AM USING DAYS BECASUE I PERSONALLY THINK IT IS MORE ACCURATE.
DAYS="days,"
HRS=" hrs"
# LET'S CHECK UPTIME IN REAL TIME. DON'T TRUST YOUR EXTENSION ATTRIBUTE FOR REAL TIME EXECUTIONS!
DAYS_check=$(uptime | awk {'print $4'})
# UPTIME CAN GIVE YOU MINUTES, HOURS OR DAYS. CHECK IF THE WORD 'DAYS' IS IN THE STRING
if [ $DAYS_check = "$DAYS" ]; then
# USE AWK AND SED TO CLEAN UP, ISOLATE AND CHECK IF THE DAYS IS MORE THAN 7
result=$(uptime | awk {'print $3'} | sed 's/,/ /g' | sed 's/d/ d/g')
if [ $result -gt "10" ]; then
# ALL GOOD. GO AHEAD LET'S ECHO SOMETHING FOR JAMF
echo "*** 10 DAYS VALIDATION: OK"
# THEN PUT YOUR CODE HERE, OR CALL ANOTHER POLICY WITHT THE RESTART MESSAGE
/usr/local/bin/jamf policy -event <<policy to restart the computer>>
exit 0
else
# UPTIME IS NOT GREATER THAN 10 DAYS, LET'S ECHO SOMETHING FOR JAMF AND GET OUR OF HERE!
echo "*** 10 DAYS VALIDATION: User restarted. Restart message will not show. ABORT! ABORT! ABORT! ABORT!"
fi
exit 0Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
