Skip to main content

I have seen bunch of scripts online but if someone has a working script which can deploy will be very helpful.



I am looking a script which checks the last reboot of the machines. Then it would check if the reboot occurred less than 7 days or not. If the user hasn't rebooted for more than 7 days, the script will restart their machines. They will receive a popup that their laptop will be restarting and also allows them to extend the time by few hours before the laptop restarts.

@egusman I used @atomczynski11's script above. We haven't implemented a 7-day reboot policy yet but wanted to make sure I had something ready. When I tested it, everything worked fine. After my device was online for over 7 days it fell into a smart group which I have my policy scoped to. 
I was able to delay it if I wanted to or reboot it. I did change the delay options times in the script. 

#!/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

 


I test with your script with self-service , after reboot , the status of this policy is pending not completed.

Can i know what is wrong with me?

 


I test with your script with self-service , after reboot , the status of this policy is pending not completed.

Can i know what is wrong with me?

 


Do you have the policy "Execution Frequency" set to "Ongoing". If so, that's probably why. If you have it available in Self Service for testing purposes only you can change the "Execution Frequency" to "Once per computer".


Do you have the policy "Execution Frequency" set to "Ongoing". If so, that's probably why. If you have it available in Self Service for testing purposes only you can change the "Execution Frequency" to "Once per computer".


The policy only for per computer once time. But i will let user  restart without immediately. 

Another thing, because i would like everything is automation executed task.

A matching Machine >  Smart Group (7days without Reboot) > Policy execute Reboot > Do Recon > Remove Smart Group. 

In the policy i put the inventory but look like machine can not have the correct uptime because user select option delay 10' minutes reboot. 

 sudo jamf policy

 

Checking for policies triggered by "recurring check-in" for user "test"...

Executing Policy _04.Schedule 7 days Reboot

Running script Schedule 7-days Reboot...

Script exit code: 0

Script result: Button clicked was: 1

Time chosen was: 300

Time in minutes: 5

Restart button was clicked. Initiating restart in 5 minutes

shutdown: [pid 2283]

Shutdown at Fri Jul 19 09:53:19 2024.

 

                                                                               

*** System shutdown message from test@VNHOCLT0186.local ***                  

 

System going down in 5 minutes                                                 

 

                                                                               

Checking for patches...

No patch policies were found.

Running Recon...

Retrieving inventory preferences from https://trustiq.jamfcloud.com/...

Finding extension attributes...

Locating hard drive information...

Locating accounts...

Locating applications...

Locating package receipts...

Locating software updates...

Locating printers...

Gathering application usage information from the JamfDaemon...

Searching path:

Searching path: /Library/Internet Plug-Ins

Searching path: /System/Applications

Searching path: /Applications

Locating hardware information (macOS 14.5.0)...

Submitting data to https://trustiq.jamfcloud.com/...

<computer_id>8</computer_id>

Submitting log to https://xxx.jamfcloud.com/