Skip to main content

Anyone has a reboot script that Allows deferral and uses Jamf Helper?. Would like to attach it to an apple updates policy. After the policy runs, it should prompt the user to restart the machine. The user should be allowed to postpone that reboot at least once before it reboots on its own. I have seen some that uses CocoaDialog. We cant/wont use Cocoadialog here at our company.

After adding the space backslash at the end of each line, at least now my log only shows one rogue line vs 9. It's promising now but it's starting to look as if the script is unable to find the file in the tmp subfolder.

Script result: /Library/Application Support/JAMF/tmp/Jamf Helper Reboot Script with Deferral: line 159: -windowType: command not found

 


Mind if I see lines ~138-168 from your script one more time since the edits?


Mind if I see lines ~138-168 from your script one more time since the edits?


Sure. Here are those lines.

if [ $diffDays -ge 4 ];then

#echo "4 days or more. Running Reboot script"
file=$(find /usr/local/jamfconnect/pmglarge.jpg)
if [ ! -z "$file" ]
then
useIcon=/usr/local/jamfconnect/pmglarge.jpg
#echo "found"
else
useIcon=/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertCautionBadgeIcon.icns
#echo "not found"
fi

else
#echo "3 days or less. Exiting"
exit 0
fi

jamfHelper()
{
"/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
-windowType utility \\
-title "PMG Mac Systems Admin" \\
-heading "It's time to reboot" \\
-description "This computer has not restarted since $lastBootFormat. Restart now or choose a delay option." \\
-icon "$useIcon" \\
-iconSize 110 \\
-button1 "Delay" \\
-button2 "Restart Now" \\
-showDelayOptions "120, 300" # 2 minutes, 5 minutes \\
}

 


Sure. Here are those lines.

if [ $diffDays -ge 4 ];then

#echo "4 days or more. Running Reboot script"
file=$(find /usr/local/jamfconnect/pmglarge.jpg)
if [ ! -z "$file" ]
then
useIcon=/usr/local/jamfconnect/pmglarge.jpg
#echo "found"
else
useIcon=/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertCautionBadgeIcon.icns
#echo "not found"
fi

else
#echo "3 days or less. Exiting"
exit 0
fi

jamfHelper()
{
"/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
-windowType utility \\
-title "PMG Mac Systems Admin" \\
-heading "It's time to reboot" \\
-description "This computer has not restarted since $lastBootFormat. Restart now or choose a delay option." \\
-icon "$useIcon" \\
-iconSize 110 \\
-button1 "Delay" \\
-button2 "Restart Now" \\
-showDelayOptions "120, 300" # 2 minutes, 5 minutes \\
}

 


Looks like you're missing a backlash after the first line 🙂 and you also won't need the backlash after the last line with the "showDelayOptions" as the command technically ends there. That'll also cause it to stop in it's tracks.

Have a look at this for reference
___________________________________
"/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper" \\
-windowType utility \\
-title "PMG Mac Systems Admin" \\
-heading "It's time to reboot" \\
-description "This computer has not restarted since $lastBootFormat. Restart now or choose a delay option." \\
-icon "$useIcon" \\
-iconSize 110 \\
-button1 "Delay" \\
-button2 "Restart Now" \\
-showDelayOptions "120, 300" # 2 minutes, 5 minutes


Looks like you're missing a backlash after the first line 🙂 and you also won't need the backlash after the last line with the "showDelayOptions" as the command technically ends there. That'll also cause it to stop in it's tracks.

Have a look at this for reference
___________________________________
"/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper" \\
-windowType utility \\
-title "PMG Mac Systems Admin" \\
-heading "It's time to reboot" \\
-description "This computer has not restarted since $lastBootFormat. Restart now or choose a delay option." \\
-icon "$useIcon" \\
-iconSize 110 \\
-button1 "Delay" \\
-button2 "Restart Now" \\
-showDelayOptions "120, 300" # 2 minutes, 5 minutes


That worked!! Thank you so much for tips and the reasoning behind it. That makes learning this very helpful.


That worked!! Thank you so much for tips and the reasoning behind it. That makes learning this very helpful.


You're very welcome! Glad we could get that working 👍 In the spirit of breaking it down. Here is essentially how terminal would run the line with those backlashes in place. 

This is also another format you could use in the script to have it run that Jamf Helper prompt. (All in the same line). Hope that helps even more, have a great day!

"/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper" -windowType utility -title "PMG Mac Systems Admin" -heading "It's time to reboot" -description "This computer has not restarted since $lastBootFormat. Restart now or choose a delay option." -icon "$useIcon" -iconSize 110 -button1 "Delay" -button2 "Restart Now" -showDelayOptions "120, 300" # 2 minutes, 5 minutes

 


You're very welcome! Glad we could get that working 👍 In the spirit of breaking it down. Here is essentially how terminal would run the line with those backlashes in place. 

This is also another format you could use in the script to have it run that Jamf Helper prompt. (All in the same line). Hope that helps even more, have a great day!

"/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper" -windowType utility -title "PMG Mac Systems Admin" -heading "It's time to reboot" -description "This computer has not restarted since $lastBootFormat. Restart now or choose a delay option." -icon "$useIcon" -iconSize 110 -button1 "Delay" -button2 "Restart Now" -showDelayOptions "120, 300" # 2 minutes, 5 minutes

 


That is also a "good to know" way to use a script. I personally prefer the separate lines to make things easier to read than to horizontally scroll. But to each their own and your knowledge has been passed to me in a positive way. Cheers!


Do any of your gents have and still use a full working version of this Reboot script?


Do any of your gents have and still use a full working version of this Reboot script?


@rcole It's been a couple of years since I tested the one I'm using. It's one I got from this other post. However, the last time I tested it things worked as designed. Here's the settings I have configured (I changed the defer times). I was going to setup a policy and smart group to target devices that hadn't rebooted in the last 7 days and run this script on them. I hadn't gotten around to implementing it yet since I first tested it.


#!/bin/bash

###################
### Adam T.
### April 16, 2020
### This is a JamfHelper Script which will be used to notify user if they have not restarted the computer in 7 days
### This script will give the user options how to proceed (now, 1 min, 5 min, 30 min 1 hr, 2 hrs as an example)
### This is needed as staff members tend not to restart their computers often
### This script is called from another script that checks uptime
##################
### Using Jamf Helper is cool
#################



#Message type variables below

#Utility window gives a white background
window="utility"
title="Reboot Needed"
heading="IMPORTANT: A system reboot is required. Please close all applications and restart your computer."
description="Your computer has not been restarted in at least seven days. A more frequent restart is recommended.
Doing so optimizes the performance of your computer as well as allows us to deploy security updates or new applications to you automatically.

To prevent receiving this message in the future, please reboot your computer at least once per week.
NOTE: Use the dropdown below to select a time of when you want to reboot then click Restart. Your device will reboot automatically based on the time you selected."

icon="/System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns"




selection=$("/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper" -windowType "$window" -title "$title" -heading "$heading" -description "$description" -icon "$icon" -button1 "Restart" -showDelayOptions "0, 60, 3600, 7200, 14400, 28800")
## The Original line below
#selection=$("/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper" -windowType "$window" -title "$title" -heading "$heading" -description "$description" -icon "$icon" -button2 "Restart" -showDelayOptions "0, 60, 3600, 7200, 14400, 28800" -button1 "Cancel" -cancelButton 1)

buttonClicked="${selection:$i-1}"
timeChosen="${selection%?}"

## Convert seconds to minutes for restart command
timeMinutes=$((timeChosen/60))

## Echoes for troubleshooting purposes
echo "Button clicked was: $buttonClicked"
echo "Time chosen was: $timeChosen"
echo "Time in minutes: $timeMinutes"

#Changed Line 49 and 52 from 2 to 1
if [[ "$buttonClicked" == "1" ]] && [[ ! -z "$timeChosen" ]]; then
echo "Restart button was clicked. Initiating restart in $timeMinutes minutes"
shutdown -r +${timeMinutes}
elif [[ "$buttonClicked" == "1" ]] && [[ -z "$timeChosen" ]]; then
echo "Restart button was clicked. Initiating immediate restart"
shutdown -r now
#elif [ "$buttonClicked" == "1" ]; then
#echo "Cancel button clicked. Exiting..."
exit 0
fi


exit