Shutdown instead of Reboot after policy execution

Valued Contributor

I would like to shut down a machine after a policy triggered by logout has completed.
Casper offers the "Reboot" option, but no shutdown.

If I append a shutdown -h now command to the policy,
there is no Log written to the JSS because the client goes down straight away.

Currently I see two ways to get around this:

First, shutdown -h +1 instead of now - not that elegant

Second, make two policies, one containing the actual commands, with a custom trigger,
the other one triggering the first policy and shutting down afterwards - two policies for one job, don't like that either ;)

Any of you geniuses with a hint for me?



I haven't tested this to see if it will write to the JSS but you can add an ampersand to the end of a line to put the process into the background:

shutdown -h +10 &

That allows the rest of the script to proceed in parallel and may give the machine a chance to complete reporting to the JSS.

Contributor III

Hi Chris

I've created this script for the task of logging to jamf.log
Upload to Casper and run it after your policy.
Let me know if helps.



# format day and time as per jamf log.
$DATE= localtime(time);
@DATE =split (' ',$DATE);
$DATE=$DATE[0]." ".$DATE[1]." ".$DATE[2]." ".$DATE[3];

open(LOG, ">>$log") || die "Can't open log file: $! ";
# Entry to jamf.log
print LOG "$DATE This mac is shutting down now.... ";

close (REPORT);

# shut down command.
$command="shutdown -h now";

exit 0; ## Success
exit 1; ## Failure