背景
没有脚本时,关闭集群里的Linux机器,需要分别在每台机器执行关机命令,费时费力。
[hadoop@node2 ~]$ sudo init 0 [hadoop@node3 ~]$ sudo init 0 [hadoop@node4 ~]$ sudo init 0
编写脚本
在~/bin
目录下,新建guanji.sh
脚本文件
[hadoop@node2 bin]$ nano guanji.sh
脚本内容
#!/bin/bash
for host in node4 node3 node2
do
echo =============== $host ===============
ssh $host sudo init 0;
done
添加权限
[hadoop@node2 bin]$ chmod u+x guanji.sh
测试
[hadoop@node2 bin]$ guanji.sh =============== node4 =============== Connection to node4 closed by remote host. =============== node3 =============== Connection to node3 closed by remote host. =============== node2 =============== Connection closing...Socket close. Connection closed by foreign host.
完成!enjoy it!