SoFunction
Updated on 2025-03-09

Use the plink tool to achieve remote batch shutdown in the shell

My operating system is centos6.4

Operating system: rhel 6.2 x86_64

Download and install the putty software package. I downloaded putty-0.62-1..x86_64.rpm
The download address is as follows: /index.php3

1. Remote host IP list file

Copy the codeThe code is as follows:

[root@localhost~]# vim server_list.txt

192.168.0.13
192.168.0.12
192.168.0.11


2. Files of operations to be performed by the remote host
Copy the codeThe code is as follows:

[root@localhost~]# vim

shutdown -h now

3. Remote shutdown automation script

Copy the codeThe code is as follows:

[root@localhost~]# vim remote_shutdown.sh

for i in `cat server_list.txt`
do
plink -l root $i -pw redhat -m / <<EOF
y
EOF
done


4. The script gives execution permissions x
Copy the codeThe code is as follows:

[root@localhost~]# chmod a+x remote_shutdown.sh

5. Script running
Copy the codeThe code is as follows:

[root@localhost~]# ./remote_shutdown.sh

Note: In my application environment, all host root user passwords are redhat. Please adjust them according to the actual environment. If there is no rule, you can list them in a single item.

For example:

Copy the codeThe code is as follows:

vim remote_shutdown.sh

plink -l root 192.168.0.12 -pw password1 -m /
plink -l jane 192.168.0.35 -pw password2 -m /
plink -l paul 192.168.0.77 -pw password3 -m /
plink -l root 192.168.0.19 -pw password4 -m /
 
(or plink [email protected] -pw password4 -m /)