Skip to main content
Question

Shutdown instead of Reboot after policy execution


Forum|alt.badge.img+13
  • Valued Contributor
  • 268 replies

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?

2 replies

talkingmoose
Forum|alt.badge.img+36
  • Community Manager
  • 1900 replies
  • January 27, 2012

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.


Mauricio11
Forum|alt.badge.img+11
  • Valued Contributor
  • 173 replies
  • February 9, 2012

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.
Regards
Mauricio

###############
#!/usr/bin/perl

$pathToScript=$0;
$pathToPackage=$ARGV[0];
$targetLocation=$ARGV[1];
$targetVolume=$ARGV[2];

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

$log="/var/log/jamf.log";
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";
`$command`;

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings