EOFFJM
Posts: 22
Joined: Thu Jan 24, 2019 6:23 pm

Shut down multiple raspberry pis via SSH at once

Thu Jul 18, 2019 12:26 pm

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.

User avatar
RaTTuS
Posts: 10409
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Shut down multiple raspberry pis via SSH at once

Thu Jul 18, 2019 12:37 pm

How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

User avatar
B.Goode
Posts: 8240
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Shut down multiple raspberry pis via SSH at once

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.

jahboater
Posts: 4598
Joined: Wed Feb 04, 2015 6:38 pm

Re: Shut down multiple raspberry pis via SSH at once

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.

EOFFJM
Posts: 22
Joined: Thu Jan 24, 2019 6:23 pm

Re: Shut down multiple raspberry pis via SSH at once

Thu Jul 18, 2019 1:47 pm

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...

EOFFJM
Posts: 22
Joined: Thu Jan 24, 2019 6:23 pm

Re: Shut down multiple raspberry pis via SSH at once

Thu Jul 18, 2019 1:48 pm

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.

jahboater
Posts: 4598
Joined: Wed Feb 04, 2015 6:38 pm

Re: Shut down multiple raspberry pis via SSH at once

Thu Jul 18, 2019 1:53 pm

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!)

Return to “Raspbian”