Posted on 08-25-2015 10:08 AM
Hi all,
Is there a way in Casper for the end user to be prompted once a week to reboot their machines? We all know the Mac can run for weeks upon weeks before a reboot is really needed. From a corp standpoint we want to have users at a minimal reboot them weekly just to make sure the memory is cleared, and programs run a lot more smoothly. Any ideas how we can accomplish this?
Thank you
Posted on 08-25-2015 10:21 AM
Yeah, I suppose you could simply go with the Casper Suite built in options, using the Restart Options section of a policy, along with the User Interaction tab to set up a message explaining that the Mac will reboot in x minutes. You'd just need to set the Execution Frequency to once per week.
The only potential issue with using the built in option is that it waits until the user clicks the OK button before starting the x minutes countdown, which may or may not what you want.
To get around that, you can run a script instead that does the jamf reboot command but puts it into the background, meaning it won't wait for an OK button to be clicked before starting the countdown to reboot.
jamf reboot -minutes 10 -message "Your Mac will reboot in 10 minutes to maintain smooth working order. Please close any open work now to avoid data loss of unsaved documents." -background
Or, you could take a look at one of my scripts on my github page which let's you set up scheduled reboots in the future and gives the user a 5 minute warning prior to the actual reboot.
https://github.com/mm2270/CasperSuiteScripts#reboot_schedulersh
Posted on 08-25-2015 11:11 AM
Is there a way so that a box pops up warning them more then allowing them to click a button to reboot it? Its more of an FYI...
Posted on 08-25-2015 11:26 AM
Oh, yeah, you can do that too. Didn't know you just wanted a warning. If that's all you're looking for, use either the User Interaction tab with no reboot set in the Reboot Options, or script something to run once a week using jamf displayMessage, or jamfHelper or cocoaDialog, etc. with the message you want. In the end, the mechanism you use for the message isn't that important. The important piece is making it run on the check in trigger but with an execution frequency of once per week to get the desired once a week reminder you're looking for.
Another thing - if you decide to do this, I'd encourage you to also do some searches for other threads that show how some admins are using Extension Attributes to capture uptime and then scope the policy for the message to Macs that exceed a certain number of hours/days, etc. I guess what I'm saying is, it would be annoying to me as a user if I had just restarted my Mac a few minutes ago and I got a pop up telling me to restart my Mac a little while later. You need to make this more intelligent, so the script should probably check the uptime and see if its beyond a certain value before it shows any message. otherwise you're just annoying people.
Posted on 08-25-2015 12:01 PM
Just to follow up and make this more helpful, here is an example script that you can have run on any schedule you want that would only send up a message (in this case using jamfHelper) to tell the user to reboot if they have exceeded the maxHours value as a threshold for uptime. Otherwise it exits silently.
#!/bin/bash
jHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
maxHours="120" ## 120 hours = 5 days in hours. Change to any value you want as the max threshold
timeNow=$(date +"%s")
upTimeSecs=$(sysctl kern.boottime | awk -F'[= |,]' '{print $6}')
upTimeHours=$(($((timeNow-upTimeSecs))/60/60))
echo "Uptime hours: $upTimeHours"
msg="Your Mac has now been running for at least $upTimeHours hours between reboots.
Please reboot your Mac as soon as its convenient to in order to maintain smooth operation of your system."
icon="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/Toolbarinfo.icns"
if (( $upTimeHours >= $maxHours )); then
echo "Mac has been up for more than $maxHours hours"
"$jHelper" -windowType utility -description "$msg" -button1 OK -icon "$icon" -iconSize 90
exit 0
else
echo "Mac has been up for less than $maxHours hours. Exiting."
exit 0
fi
My reasoning for posting this is because although it can be great to have an uptime Extension Attribute on your JSS (we have one), its always just a snapshot in time. Unless your Macs are submitting inventory constantly, the uptime value is never going to be that accurate. We only use ours for generalized reporting.
You can use the above script to run once a day on all Macs. Only Macs that have been up for as long or longer than the specified time would actually get a message.
Hope it helps or gets you started in the right direction.
Posted on 08-25-2015 12:11 PM
Thank you, that is perfect. So where would I place this script though?
Posted on 08-25-2015 12:34 PM
JSS > Computer Management > Scripts
Create a new script. Name it whatever you want and copy/paste the above, making whatever changes to dialog, max hours value, etc you want to.
Save it and then create a test policy and add the script you just made to it. Set trigger, execution frequency and scope for the policy to test.
Edit Or, you might have to use a plain text editor (no, not TextEdit, something like TextWrangler) and copy/paste it there, save it, then upload into your JSS via Casper Admin. Not sure how your JSS is set up.
Posted on 08-25-2015 02:29 PM
I actually run an extension attribute that tracks uptime. I have a Smart group that collects any Machines whose uptime exceeds 7 (but less than 14) days. I then have a once a week policy that sends a script to that group which pops a message reminding them to restart at their earliest convenience.
After they have exceeded 14 days and beyond they are picked up by a different smart group which trigger a daily policy sending the same message.
Usually the constant annoyance of having to click the message off is enough to get them to reboot. I've been considering having a 30+ day group which gives a 5 minute warning and then just flat out reboots for the few that just refuse to comply.
I of course keep test boxes and servers and special cases out of these policies.
Posted on 08-26-2015 01:44 PM
Thanks. I inputted that script but what do you set the smart group criteria to once you have it setup? What operator and what value? Sorry still a newbie here...
Posted on 08-26-2015 02:06 PM
Hi @rkovelman Just a quick question, but have you been through a JumpStart or attended any Casper Suite training, or looked through the manual that comes with the product? I ask because I can see you're asking some very basic questions, which is fine. We're all here to help, but none of our jobs is to help someone learn Casper Suite from scratch. Some of the work must be done on your end. I would get yourself a copy of the manuals, particularly the QuickStart guide, which is good for learning specific tasks, and start getting more familiar with this stuff. Maybe you've already began that process, but just thought I'd mention it. I'm not trying to discourage you from asking questions, so please don't take it that way. Just that I want to be sure you are also working on learning this from your own perspective and not relying solely on the forum.
As for your question, how you scope this is going to be up to you really. Since my script relies on the actual uptime of the Mac it runs on (IOW, its doing a live pull of the uptime) and not on a value for a Smart Group, you could technically scope it all managed computers, rather than any particular Smart Group. I would be careful with that though and first create a manual test group of machines to gauge how it runs, and most importantly, if it works. Later you can expand the scope of this.
What's also going to be important is the trigger and execution frequency. I'd probably just use the Check-in trigger, but maybe set frequency to once per week, at least to start with. For testing purposes, you could drop that down to Ongoing and Check-in trigger. If a Mac in scope has been "up" for as long or longer than the specified hours, the pop up message should occur each time the check-in happens.
Let me know if the above helps.
Posted on 08-26-2015 02:27 PM
@mm2270 Yes we have gone through the jumpstart, and I do have quite a bit of smart groups, but nothing to this extent with a custom script and everything. We are fairly competent with everything, this is just a bit more than we currently know.
Posted on 08-26-2015 03:09 PM
@rkovelman Ah, I think I see where the confusion is coming in here. I'm sorry if I didn't make it more clear, but the script that I posted above is not intended to be used to build a smart group. It's just supposed to be used in a policy.
If you want a script that will help build a smart group, then what you're looking for is an extension attribute.
If that's what you want, then up at my previous post where I posted a link to my github page, I have an extension attribute script that will gather the uptime on your Macs.
Mine is certainly not the only one though, so feel free to look around at other peoples Extension Attribute scripts for uptime.
Hope that helps.
Posted on 01-26-2017 02:26 PM
@mm2270 Is there a way to run this every 30 minutes or something? The script does work but its either once a day or ongoing, which can be a pita to the end user if they will reboot at EOD vs midday.