Skip to main content
Question

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


Forum|alt.badge.img+4

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

talkingmoose
Forum|alt.badge.img+36
  • Legendary Contributor
  • 1900 replies
  • August 4, 2020

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
Forum|alt.badge.img+36
  • Legendary Contributor
  • 4293 replies
  • August 4, 2020

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


Forum|alt.badge.img+4
  • Author
  • Contributor
  • 22 replies
  • August 5, 2020

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.


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