Shutdown command in bash script - can't detach from console

mnickels
New Contributor III

Hello everyone,

I'm using a tweaked version of the update script found on this forum. The tweaked version will detect if a macOS update requires a reboot, or a full shutdown.

In the even that a full shutdown is required, I run the command "shutdown -h +1". This command works great on my own Mac, and in my testing on a VM (both manually and through a Jamf policy).

I've since deployed this script to the first round of test computers, and in the log file I'm receiving the following on all of them:

shutdown: [pid 53833]
Shutdown at Mon Aug 3 22:12:57 2020.
shutdown: can't detach from console

It doesn't look like the shutdown is actually occurring, and I'm not finding much on Google for what "can't detach from console" means, or alternative methods of initiating a shutdown.

Has anyone seen this error before? Is there a different/better way to initialize a shutdown, or does anyone know what could cause this error?

3 REPLIES 3

talkingmoose
Moderator
Moderator

Try adding an ampersand ( & ) to the end of your command. This spins off the command to its own process and should allow the policy to complete its process. Something like:

shutdown -h +1 &

donmontalvo
Esteemed Contributor III

A wise man named Bill once told us to use && shutdown or && reboot At the end of our script.

--
https://donmontalvo.com

mnickels
New Contributor III

Thanks for the suggestions, I will give them a shot.

EDIT: I went with the first suggestion of "shutdown -h +1 &". Although the result of the command is no longer returned in the Jamf log, this does appear to be working as I'm seeing the machines get successfully updated. Thanks again.