How to poweroff multiple linux machines in a single command or script?

I have more than 10 Linux machines. How may I power off all machines using a single script?

The password and user is the same for all of the machines.

Answer

There’s many mays to do it.

One option is to use ssh key pairs instead of passwords to ssh without prompting for password. Then, you can do this :

#!/bin/bash

for server; do ssh $server 'halt; exit'; done

Usage:

./script.bash server1 server2 1.2.3.4

Or you can use a better approach with a tool like or pssh

Leave a Reply

Your email address will not be published. Required fields are marked *