Shell script to Shutdown Computers on Cluster

Hello all.

I have built a cluster of 9 Macs for computational chemistry and I need a shell script that I can use from one computer to all the rest to shutdown.

I have modified all of the Macs so that there is pass-wordless ssh. As well, I have modified each "visudo" file on each machine by adding the line

The computer names are as follows: G5-1, G5-2, G5-3, etc up to G5-9. There are also two named G4-1 and G4-2.

If I type in a terminal

then G5-2 will shutdown.

What I was wondering was is there a way to write a script that I can execute from the main machine (which is G5-1) that will send this line to all of the machines and then wait 2 minutes and shut itself down?

That is, the script would send the shutdown command to G5-2, G5-3, G5-4, G5-5, G5-6, G5-7, G5-8, G5-9, G4-1 and G4-2. Then wait 1 minute and then shut itself down.

Please help.

Thanks.

put your server list in a file, such as

$ cat Server_list
G5-1
G5-3
G5-4
...
G5-9

run below script Down_all

$ cat Down_all

cat Server_list |xargs -i ssh {} "sudo shutdown -h now"
sleep 120
sudo shutdown -h now

or

for i in `cat Server_list`
do
  ssh $i "sudo shutdown -h now"
done
sleep 120
sudo shutdown -h now