Shutting down a networked mac

I have two macs: an iMac, running Catalina, and an old MacPro running Lion.
The MacPro startups on midday Sundays.
Then, Carbon Copy Cloner does a backup of my iTunes Library (that’s on an external HD).
Usually the backup takes a few minutes. After 15 minutes the MacPro shuts down.
It works, but it’s unsatisfactory.
What I would like to happen is that Carbon Copy Cloner (CCC) shut the MacPro when it finishes the backup.
CCC can do that. It requires an unix script, but I don’t have enough knowledge to write it.
I would be grateful if anybody has an Unix script to remote shutdown another Mac.
Regards, and Happy Holidays! to all from Buenos Aires, Argentina.
Francisco Hirsch

OK so far.

Does this mean that the iMac is always on?

Is CCC running on the MacPro or the iMac?

If CCC is running on the MacPro, that’s fairly easy, but it sounds like perhaps CCC is running on the iMac, and you want it to shut down the MacPro once CCC on the iMac is done.

That’s do-able but would require configuration in Terminal on both Macs. Is that something you’re comfortable doing?

CCC is running on the iMac
The MacPro Starts up and Shuts down automatically at specified times (15 minutes after startup).

I want CCC (via Unix script) to shut down the MacPro when it finishes the backup so if it has a lot to backup it can do it in one instance.

The 15 minute period is ok most of the time as very little has to be copied (again most of the time).

CCC has an option to run Unix scripts at the end of a scheduled run
Regards,

Francisco

Got it. Well, I don’t know the full details of the setup, of course, but it seems like it would be a lot easier to have CCC run on the MacPro on startup, and then it could easily shut itself off when it was done.

However, I am assuming that you have disregarded that option for some important reason.

Let’s start at the finish…

Once everything is in place, the script to use with Carbon Copy Cloner would look like this:

#!/usr/bin/env zsh -f

PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin

ssh MyUserName@MacProHostname.local. 'sudo /sbin/shutdown -h now'

exit 0

Where you will need to change MyUserName and MacProHostname.

If your username on the Mac Pro is the same as on the iMac, you can remove the MyUserName@ part entirely.

Step 1: Passwordless SSH between your iMac and Mac Pro

You need to create a SSH key on your iMac using ssh-keygen and then install it on the Mac Pro.

This is a multi-step process, but there are lots of guides out there on how to do this. At the end, you should be able to do:

ssh MyUserName@MacProHostname.local. hostname

and get the name of the MacPro without having to enter a password.

Step 2: Tell your MacPro to allow sudo shutdown without password

Log in to the MacPro. Launch Terminal.app from the “/Applications/Utilities/” folder. Then paste this line:

sudo pico /etc/sudoers.d/mysudoers

(The first time you use sudo you will see a warning. Read it, but don’t let it scare you off.)

Enter your login password when prompted.

Then paste this line:

%admin ALL=NOPASSWD: /sbin/shutdown

Press Control+X to exit the file and press Y when prompted to save it.

Step 3: Testing

Once you think everything is in place, you should be able to run this in Terminal to reboot the MacPro:

ssh MyUserName@MacProHostname.local. 'sudo /sbin/shutdown -r now'

Note that shutdown -r now is “Reboot” and shutdown -h now is “Halt” aka “Power Down”.

Once you have that working, you should be able to use the script above in CCC.

Caveat

Actually, there’s a snag I had not thought of. I think the scripts in CCC run as root rather than your own user.

If that’s the case, it adds another wrinkle. I don’t have time to test / verify right now, but get started on Steps 1-3 and then we can move on to getting it to work with CCC.

3 Likes