close_machines.sh

#!/bin/bash
#1.loop down all machines;2.Write a script to shut down all hosts except yourself;3.When the script is executed, the ssh key must be delivered to all other hosts in advance to ensure password-less connection

for i in {244..246}
do
  [ $i -eq 244 ] && continue
  echo "shutting down 192.168.10.$i..."
  ssh 192.168.10.$i poweroff
done
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.

验证:

[root@logstash ~]# sh close_machines.sh 
shutting down 192.168.10.245...
Connection to 192.168.10.245 closed by remote host.
shutting down 192.168.10.246...
ssh: connect to host 192.168.10.246 port 22: No route to host
[root@logstash ~]#
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.