JAMF Nation folks! I am in need of some advice on how to restart a computer within a if-else/else-if loop of a JAMF Helper script. The script's purpose is to perform software and security updates and then reboot the computer if the user decides to opt in. If not, an echo command is sent and they'll be prompted again the following day. The opt-in and opt-out portions work great and the updates are applied. The only issue here is with the actual restarting of the computer.
if [ "$userChoice" == "0" ]; then
echo "User clicked UPDATE; now downloading and installing all available updates."
softwareupdate --install --all
osascript -e 'tell application "System Events" to restart'
elif [ "$userChoice" == "2" ]; then
echo "User clicked Cancel or timeout was reached; now exiting."
exit 0
fi
The problematic line is osascript -e 'tell application "System Events" to restart'. An error is generated as well within the JSS logs. Here's the error that is received.
36:43: execution error: An error of type -10810 has occurred. (-10810)
The error here pertains to access rights and not being able to run with elevated permissions--i.e. sudo. Is there a work-around to get this to restart?