Computing uptime and notifying users of long uptime with Yo Scheduler

Frances_R
New Contributor II

Hi, I have searched up and down for an answer and being a little bit new to this I'm not sure how to create a script - I've seen scripts for this purpose for Growl and CocoaDialog but I am using Yo Scheduler, and what I'd like to do is send notifications to users with uptime of +7 days. I have already created a package adds the executable in Applications/Utilities and the command line script to /usr/local/bin/, tested it on my test computer, and it works.. the last step of course is the script, which again I can only find (in much older forums) for Growl and CocoaDialog. Anyone have any experience with Yo for this specific task? Sorry about the brevity, again, a little new to this, let me know if you need more information.
Thanks all!

3 REPLIES 3

davidacland
Honored Contributor II
Honored Contributor II

Hi,

If you have scripts that leverage Growl or CocoaDialog, the logic would be pretty similar for Yo.

You could also use either jamfhelper, or the built-in management notifications from jamf to avoid adding a separate dependency to the machine.

Do you already have the code to check if a Mac has been up for more than 7 days, and just need help with the notification part?

My recommendation would be to use a bit of trial and error and post bits you’re stuck on. That way you will understand it much better if/when it breaks.

m_donovan
Contributor III

You could do something like this:

#!/bin/bash

lastBootRaw=$(sysctl kern.boottime | awk -F'[= |,]' '{print $6}')

#today=$(date +%s)
today=$(date -v+7d +%s) ###########For Testing #############################################

diffDays=$(( (today - lastBootRaw) / 86400 ))

if [ $diffDays -ge 7 ];then

    /Library/Application Support/JAMF/bin/Management Action.app/Contents/MacOS/Management Action -message "Your computer has not rebooted in $diffDays days."

fi

exit 0

Comment out the "For Testing" line and uncomment the one above for live use. Put it in a once a day policy and you at least inform the user.

howie_isaacks
Valued Contributor II

I inform users with a message displayed asking them to reboot as soon as possible. I set this up to run at check in once a day. Most seem to ignore it. After 20 days, the message pops up every time the system checks in. Some persistent users ignore it. Now I'm thinking of restricting use of web browsers to get them to reboot. I already do this if someone disables SIP. I have some developers that I support, and even though I have asked them not to disable SIP, some still do it. When they do, it makes their Mac fall into scope for the restricted software policies that I have setup. They won't be able to use a web browser until they disable SIP.