Posted on 03-31-2022 09:50 AM
I am trying to find a way to create a policy that will restart a computer after it's been up for X number of days. I don't want it to force a reboot instantly though. I want the user to have the option to postpone it 2 or 3 times until it forces. Has anyone had any luck with this?
Solved! Go to Solution.
Posted on 03-31-2022 11:19 AM
We did something similar, though ours just requested that the user restart. Basically I created a smart group called "Report - Uptime Is Greater Than 21 Days" where the criteria is "Days Since Last Restart" is more than 21 days. I then created a policy scoped to that group that just uses the "User Interaction" tab of the policy to send a message that shows up as a notification on their screen encouraging them to restart. We've seen great success in keeping the number of users who haven't restarted in more than 21 days down since then.
Posted on 03-31-2022 04:10 PM
Hey all! I've used this EA in the past, it will format the last reboot time in a way that you can set the Data Type on the EA to 'Date (YYYY-MM-DD hh:mm:ss)'. Then with your Smart Computer Group, you'll be able to use 'more than x days ago' operator. Here is the script:
#!/bin/bash
# Get boottime in epoch time, convert to Jamf Pro formatted time and make an extension attribute
#
# Updated: 2.23.2022 @ Robjschroeder
#
bootTime=$(sysctl kern.boottime | awk '{print $5}' | tr -d ,)
formattedTime=$(date -jf %s $bootTime "+%F %T")
echo "<result>${formattedTime}</result>"
exit 0
Posted on 03-31-2022 11:19 AM
We did something similar, though ours just requested that the user restart. Basically I created a smart group called "Report - Uptime Is Greater Than 21 Days" where the criteria is "Days Since Last Restart" is more than 21 days. I then created a policy scoped to that group that just uses the "User Interaction" tab of the policy to send a message that shows up as a notification on their screen encouraging them to restart. We've seen great success in keeping the number of users who haven't restarted in more than 21 days down since then.
Posted on 03-31-2022 12:59 PM
I think that sounds great! How did you use that criteria for the smart group? I don't see anything that references reboot or or last restart. Is that a custom extension attribute?
Posted on 03-31-2022 01:51 PM
Here's a time since last reboot XATTR that I use...
#!/bin/bash
## last system reboot
btt=`sysctl kern.boottime | awk -F'} ' '{print $NF}' | awk '{print $NF,$2,$3,$4}'`
echo "<result>$btt</result>"
Posted on 03-31-2022 01:55 PM
Good question! Yes, here's the extension attribute I came up with:
#!/bin/sh
uptime=$( uptime )
dayCount=$( uptime | awk -F "(up | days)" '{ print $2 }' | sed 's/[ day].*//' )
if [[ $uptime == *"day"* ]]; then
echo "<result>$dayCount</result>"
else echo "<result>0</result>"
fi
exit 0
Posted on 03-31-2022 01:56 PM
^ that's better! 👍
Posted on 03-31-2022 01:58 PM
That one took some trial and error for sure. 😂
Posted on 03-31-2022 02:00 PM
Since I can't reboot anyone's Mac, I made one to just show date of last reboot, but for this situation, yours is much more useful.
Posted on 03-31-2022 02:06 PM
This is exactly what I wanted! Thank you so much for your help. I will created that policy and see if it helps.
Posted on 03-31-2022 02:06 PM
Awesome! Very happy I could be of service!
Posted on 05-27-2023 12:25 PM
Thank you for this!
Posted on 07-27-2022 08:34 AM
Thanks for sharing this. I'm working on implementing this myself, but I'm not quite clear on where the "...criteria is "Days Since Last Restart" is more than 21 days"
How does this look in the criteria section? Specifically the operator and value specified.
Thank you!
Posted on 07-27-2022 08:43 AM
Good question! "Days Since Last Restart" is the name of my extension attribute, so I can add it by choosing "Show Advanced Criteria" when adding criteria to my smart group. My extension attribute Data Type is set to integer, which gives me the "More Than" operator in the smart group, and I typed in "21" in the Value field.
Posted on 07-27-2022 08:48 AM
Ah ha, of course, I had selected text instead of integer, that would be the problem. Thank you!
Posted on 07-27-2022 08:55 AM
You're very welcome!
Posted on 03-31-2022 04:10 PM
Hey all! I've used this EA in the past, it will format the last reboot time in a way that you can set the Data Type on the EA to 'Date (YYYY-MM-DD hh:mm:ss)'. Then with your Smart Computer Group, you'll be able to use 'more than x days ago' operator. Here is the script:
#!/bin/bash
# Get boottime in epoch time, convert to Jamf Pro formatted time and make an extension attribute
#
# Updated: 2.23.2022 @ Robjschroeder
#
bootTime=$(sysctl kern.boottime | awk '{print $5}' | tr -d ,)
formattedTime=$(date -jf %s $bootTime "+%F %T")
echo "<result>${formattedTime}</result>"
exit 0
Posted on 09-20-2023 07:47 AM
I am pretty new to this, and I added the EA and then i create the smart computer group, when i view the results is there a way to add the uptime filed in the results to make sure the data is correct? I currently have last Check-in showing.
Posted on 09-21-2023 07:52 AM
Got it working, I was impatient and expected immediate reports,.
Posted on 10-09-2023 04:01 AM
The script and settings work but really not practical at all. During the first half of the day, it only detected 5 Mac's. With this rate it would take a whole week to extract a report.
Posted on 10-09-2023 08:27 AM
That's the joy of using an EA, your computers need to submit inventory to get the data
Posted on 10-20-2023 08:37 AM
I have the script running and now I can see last restarts.
How do I create something to where if a user hasn't restarted in x amounts of days they need to reboot/shut down laptop warning?
Posted on 10-20-2023 08:42 AM
I created a policy called "Time To Restart."
Its trigger is recurring checkin, and its frequency is once per day.
It's scoped to my "Report - Uptime Is Greater Than 21 Days" smart group.
All the policy does is leverage the User Interaction tab to display the following message as a notification:
"Your Mac hasn't been restarted in more than 21 days. Restarting your Mac at least once a week helps keep it running optimally. - IT"
I wanted to keep the wording short so it all fit within the small notification banner.
Posted on 10-20-2023 08:46 AM
I can't get the smart group to see anything, I'm missing some settings or config.
Posted on 10-20-2023 08:49 AM
Here's what my smart group criteria looks like. I've got my operator set to "more than."
Posted on 10-20-2023 10:14 AM
Thank you I appreciate it! Can I bug you for one more thing? What does your script look like?
Thanks.
Posted on 10-20-2023 01:55 PM
Sure! Here's mine:
#!/bin/sh uptime=$( uptime ) dayCount=$( uptime | awk -F "(up | days)" '{ print $2 }' | sed 's/[ day].*//' ) if [[ $uptime == *"day"* ]]; then echo "<result>$dayCount</result>" else echo "<result>0</result>" fi exit 0
Posted on 10-23-2023 03:40 AM
Good Morning John
I meant this policy for this
All the policy does is leverage the User Interaction tab to display the following message as a notification:
"Your Mac hasn't been restarted in more than 21 days. Restarting your Mac at least once a week helps keep it running optimally. - IT"
Posted on 10-23-2023 05:08 AM
Have you checked out Renew? https://github.com/SecondSonConsulting/Renew
Posted on 10-23-2023 07:53 AM
Posted on 08-26-2024 07:19 PM
Sorry for the necro but do you add anything else to the policy other than the General tab? EA is pulling the correct information, smartgroup is made properly and policy is scoped to the SG but not seeing any notifications. Wondering if self-service/LDAP sync needs to be enabled for users to see the notification?
Posted on 08-27-2024 05:10 AM
I’m glad you brought that up. I think something in Jamf has become broken with regard to notification messages. I’m going to go submit a ticket right now actually.
Posted on 08-27-2024 07:21 AM
Ahh. We are brand new to Jamf, just starting the migration process so just wanted to dig a bit deeper. Let me know what you find out!
Posted on 08-27-2024 07:33 AM
Will do!
Posted on 10-23-2023 04:58 AM
Looks exactly like mine, and my policy and smart groups.
Posted on 10-27-2023 07:02 AM
The biggest issue is that users now move the popup window to the edge of the screen to ignore it and therefore the script / policy will never be fully executed.