Execution Frequency being ignored?

johnmccrae
New Contributor II

I have a bizarre issue. I am pushing a code snippet out to my Mac Mini's that reboots them once a night. The code runs great, the policy does not. I have it set to run on Recurring Check-In / Once Every Day / with a client-side limitation of running only between 9:30pm and 6:30am.

The odd bit is that the policy executes continuously during recurring check-in but respects the client-side limitation. For example, if I call "last reboot" via terminal on any of the Mini's it shows them rebooting every 20 minutes all night long.

I'm stumped. What am I missing?
(here's a link to the code I'm using: https://jamfnation.jamfsoftware.com/viewProductFile.html?id=135&fid=477)
Cheers
john

4 REPLIES 4

alexjdale
Valued Contributor III

The problem with the shutdown command is that the jamf binary waits for it to do its thing before finishing the policy and reporting the results to the JSS. The JSS thinks the computer hasn't run it and must run it again.

The best way I have found to resolve this is by spawning a launchdaemon that restarts the system with a short delay, giving the jamf binary time to report completion to the JSS.

See: https://jamfnation.jamfsoftware.com/discussion.html?id=14940

You can modify my code to strip out the cocoadialog UI stuff, making the script the LaunchDaemon runs simply "sleep 10" and then "shutdown -r now" instead.

johnmccrae
New Contributor II

Alex, thanks very much. I'll give it a go!

Cheers

Look
Valued Contributor III

@alexjdale
Could you not just spawn a command as a seperate thread?
Something like

shutdown -r +5 &

or alternatively

(
shutdown -r +5
) &

It in theory both should seperate away from the script, wait 5 minutes allowing the logs to be submitted and then restart the machine.
If the oneliner works you might even be able to do it simply as command on a policy.

Kumarasinghe
Valued Contributor

If you use this command, the policy will submit the log to jss before it reboots.

jamf reboot -background -immediately

So in your script change this line:

shutdownAction="shutdown -r now"

to:

shutdownAction="jamf reboot -background -immediately"