Best way to use sf.system.exec to shut down a remote mac
I'm trying to script shutting down another computer on my network:
In terminal I would use:
ssh user@myremotecomputer.lan
password
sudo shutdown -h now
password
Works fine from the Terminal but I'm not sure how to use sf.system.exec
with sudo commands and make it work.
Or should I be using Automator or something like that instead?
- Christian Scheuer @chrscheuer2021-05-18 18:21:04.020Z
I'd generally advise against storing passwords in cleartext anywhere - be it in a script on your computer or (even worse, probably) in a SF script.
Instead, to have ssh access to your remote computer, you should set that up with ssh keys. This way you never have to type in the password, because you're granting your local computer access to the remote permanently (or until you remove the key entry).
I usually just google how to do this since I can't remember the steps, but it doesn't take more than 5 minutes to set up.You would then use the ssh command to run the command directly - for example:
ssh user@remotecomputer 'shutdown -h now'
Here you should set up so that you log in directly as a super user probably, to not have to do the whole sudo thing on the remote. Probably.
Note that you could also just be running SF on each machine and remote into them that way :)
Andrew Scheps @Andrew_Scheps
Ok, I'm sure it's easier than I think, but how do you run remote scripts on another machine?
Andrew Scheps @Andrew_Scheps
Found it, using
sf.soundflow.servers
- In reply toAndrew_Scheps⬆:Jesper Ankarfeldt @JesperA2021-06-29 10:33:27.201Z
Hey Andrew.
I just put a package in Beta (made it a while ago) that utilize the remote shutdown on a server.
Maybe you wanna try it out. It would be great to see if it works outside my studio.From my experience you also had to have a "Remote Host Identification" key on your computer in order to be able to use ssh shutdown. I tried to build that authentication in to the script.
Package also has wake on lan.
Guess it goes without saying it only works with mac servers.
I've started to try and find ways to do stuff with Windows now, as I changed my servers to be windows.Andrew Scheps @Andrew_Scheps
Amazing! I'll try to check this out today or tomorrow, thank you!
- In reply toJesperA⬆:
Andrew Scheps @Andrew_Scheps
It took me until today to try it and it works perfectly, thanks!
Andrew Scheps @Andrew_Scheps
@chrscheuer Can you explain the System Trigger
willPowerOff
? I've been trying this to trigger a script but it doesn't trigger whether I shut down using the Shut Down command from the Apple menu or the control-option-command-eject shortcut. How does that system event get triggered?Christian Scheuer @chrscheuer2021-07-04 12:55:46.347Z
This comes straight from this Apple notification:
https://developer.apple.com/documentation/appkit/nsworkspacewillpoweroffnotificationThere's a big chance though that user code won't have enough time to run before this happens, so we should perhaps remove it.
Andrew Scheps @Andrew_Scheps
I can't get anything to trigger so maybe remove it. It would be great if it triggered when the shutdown procedure started, but I suppose if it did it would cancel the shutdown.
- In reply toAndrew_Scheps⬆:
Jesper Ankarfeldt @JesperA2021-07-09 17:59:22.856Z
And it took me until today to see your message :) cool to know it works
- In reply toAndrew_Scheps⬆:Daniel Perez @daniel_perez
what would be the code to shutdown the mac you're on? no remote.
Andrew Scheps @Andrew_Scheps
There are a few options, check it here:
https://www.howtogeek.com/512304/how-to-shut-down-your-mac-using-terminal/#:~:text=When Terminal opens%2C type sudo,it initiates an immediate reboot.