I have a script that runs after an application is installed to alert users that they need to restart (and after 5 minutes it automatically restarts). I'm purposely using this over the built-in JSS Restart options because most software updates are done to lab computers and I don't want to have to go to each computer and click "OK" to allow the update.
#!/bin/bash -v
appName=("$4")
loggedInUser=$(stat -f%Su /dev/console)
echo $loggedInUser
#message information
msgprompthead="Software Restart Required"
msgrestart="This computer needs to restart to finish installation of the following application:
"${4}"
Please save any open files to external media. Restart will occur automatically in 5 minutes.
To restart immediately, please click Ok after closing all applications."
dialogicon="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/Resources/Message.png"
jamfhelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
restartprompt=$("${jamfhelper}" -windowType utility -heading "${msgprompthead}" -description "${msgrestart}" -icon "${dialogicon}" -button1 "Ok" -defaultButton 1 -timeout 300)
sudo -u $loggedInUser pkill -u $loggedInUser
sudo -u $loggedInUser shutdown -r +1
exit 0
I initially had it without the pkill command, but found that the computers wouldn't restart if there was an app that hung (like Excel on an unsaved spreadsheet). Adding the pkill command does indeed end all running processes, but it also seems to cancel the script so that it doesn't proceed to the shutdown command.
I also tried reversing the commands so that shutdown ran before pkill (hoping that it would tell the computer to reboot in 1 minute and that while it was waiting that 1 minute the pkill command would run). I tried running the policy with an unsaved Excel spreadsheet open (I had clicked to close it so it had the popup window up asking if I wanted to save it), but all that happened was the screen went black (except for Excel) then Excel closed and a Microsoft Error Reporting screen came up and the computer didn't reboot.
Any ideas? I definitely don't want the computer to ask a user if they want to restart because I want the whole process to be unattended except for the warning messages (which should automatically close after a given time). Is there maybe a way to run the pkill command as written but tell it to exclude the script that the JSS is running?