I'm new to this forum; please excuse any faux pas. I've been using rsync fired by a LaunchDaemon written in tcsh for several years now. It worked great on my 2008 MacBook Pro under Snow Leopard. I now have a 2014 MBP running Yosemite. I've cleared up a few conflicts, but one continues to elude me. My script works like this:

  1. I mount an external drive.
  2. launchd starts my script
  3. My script verifies that the right drive is available.
  4. My script copies some folders from my wife's computer to mine and from mine to hers.
  5. My script sends a shutdown command to my wife's computer.
  6. My script copies some folders from our backup computer to mine and from mine to it.
  7. My script sends a shutdown command to our backup computer.
  8. My script copies some folders from my computer to the external drive.
  9. My script sends a shutdown command to my computer.

    As I said, this worked fine for several years under Snow Leopard. Now that I'm running Yosemite, steps 4, 6 and 8 fail apparently without generating any errors. In the original script, I used osascript to launch an Applescript that checked a few things and then told System Events to shut down the computer. When this failed to work in Yosemite, I switched to a simple shutdown -h +1 command right in the tcsh script. This made step 8 work correctly, but did nothing for steps 4 and 6. Ideally, I would like to get back to the Applescript shutdown command because it seems cleaner: Applications get a chance to close out or even cancel the shutdown if necessary.

    One more point I should make is that I'm using ssh -f into the root user on the two other computers to send the shutdown commands. I've set the computers up with my computer's RSA keys to enable a passwordless login, so the current command is just ssh -f root@wife.local 'shutdown -h +1'.

    I have confirmed that it works to ssh to my wife's computer and shut it down manually. It is only the script that does not shutdown the other computer.

    Has anyone any idea of why this is not working in Yosemite. More importantly, any ideas of how to make it work? I would like to be able to set the backup running and then head to bed knowing that the computers will shut down when the process is completed.

Thanks in advance.

  • it only fails when accessing the other computer! – Buscar웃 Jan 31 '15 at 4:26
  • I'm sorry, Buscar, but I don't understand what you are saying. The failure I'm concerned about only occurs when by script is run by launchd. I can run the same command from Terminal and the other computer shuts down. Also, the same script is supposed to shut my computer off, but it does not. However, when I run the same code in Terminal, it does shut down. – Uniquark Feb 1 '15 at 15:48
up vote 0 down vote accepted

I think I have found the cause of the problem, or at least a supposed explanation and a way to do what I want.

It turns out that shutting down the computer seems to be simply forbidden from a daemon. I imagine that Apple considers that to be some sort of security risk, but I have not found any information about it. The one bit I found was a comment that daemons are not allowed to launch a GUI with a link to Mac Developer Library, Daemons and Agents. For what it's worth, I must have been mistaken when I wrote that Step 8 worked when I used shutdown -h +1 because I had to use this other solution in all three shutdown steps.

So, the workaround seems to be that I need an agent to watch for a signal from my daemon to shut down the computer. I'm running the main script as a daemon because it needs root access to copy files from several different users. The agent is running on each computer that will need to be shut down and the main script runs on my computer. When the main script is done with a particular computer, it sends the signal to shut that computer down, including my computer when the main script is finished.

I'm sure there are better ways to do it, but my Unix and scripting knowledge is very spotty, so I have simply set the agent up to watch a particular folder for a particular file to show up. When that file shows up, the agent deletes the file and runs the osascript command to shut the computer down. So, the signal sent by the main script is simply touch /Shutdown/Now. It's complicated, but it works well enough for me.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.