Page 1 of 1

Shut down multiple raspberry pis via SSH at once

Posted: Thu Jul 18, 2019 12:26 pm
by EOFFJM
Hi

I would like to know if there is a way to shut down multiple RPis (9 maximum) via SSH at once. Right now there is a connection to 9 RPis via SSH from a Windows 10 PC. To shut them down I connect to them via SSH (putty) one by one and then use the

Code: Select all

sudo shutdown -h now
command. This takes a lot of time to do for 9 RPis. Is there a way to shut them down all at once? Some kind of batch file or something?
Thanks.

Re: Shut down multiple raspberry pis via SSH at once

Posted: Thu Jul 18, 2019 12:37 pm
by RaTTuS

Re: Shut down multiple raspberry pis via SSH at once

Posted: Thu Jul 18, 2019 1:25 pm
by B.Goode
This takes a lot of time to do for 9 RPis. Is there a way to shut them down all at once? Some kind of batch file or something?


Yes. Some kind of batch file.


Wouldn't a .BAT file for Powershell or the DOS Command Line under Windows be trivial to create? The same Command 9 times, with just the target hostname or IP address being different?

Hint: SSH is not restricted to running interactively - you can also use it to invoke specified commands on the target (remote) host.

Re: Shut down multiple raspberry pis via SSH at once

Posted: Thu Jul 18, 2019 1:46 pm
by jahboater
Yes, that's what I would do:-

ssh pi@pi4 'sudo poweroff'

multiple times in a batch file.

Re: Shut down multiple raspberry pis via SSH at once

Posted: Thu Jul 18, 2019 1:47 pm
by EOFFJM
B.Goode wrote:
Thu Jul 18, 2019 1:25 pm
This takes a lot of time to do for 9 RPis. Is there a way to shut them down all at once? Some kind of batch file or something?


Yes. Some kind of batch file.


Wouldn't a .BAT file for Powershell or the DOS Command Line under Windows be trivial to create? The same Command 9 times, with just the target hostname or IP address being different?

Hint: SSH is not restricted to running interactively - you can also use it to invoke specified commands on the target (remote) host.
Alright great! Now I'll just have to figure out how to do that...

Re: Shut down multiple raspberry pis via SSH at once

Posted: Thu Jul 18, 2019 1:48 pm
by EOFFJM
jahboater wrote:
Thu Jul 18, 2019 1:46 pm
Yes, that's what I would do:-

ssh pi@pi4 'sudo poweroff'

multiple times in a batch file.
Cool. Got it.

Re: Shut down multiple raspberry pis via SSH at once

Posted: Thu Jul 18, 2019 1:53 pm
by jahboater
You will need password-less authentication.

ssh-keygen -t rsa
ssh-copy-id pi@pi4

Do it once for each Pi, then scp and ssh will not require a password (which is obviously bad news in a batch file!)