在/root/bin目录下创建脚本xcall.sh
[root@hadoop102 bin]# vim xcall.sh
在脚本中编写如下内容
#! /bin/bash
for i in hadoop102 hadoop103 hadoop104
do
echo --------- $i ----------
ssh $i "$*"
done
修改脚本执行权限
[root@hadoop102 bin]# chmod 777 xcall.sh
启动脚本

本文介绍了一个用于在多个远程服务器上批量执行相同SSH命令的Shell脚本。通过编写一个简单的bash脚本xcall.sh,可以在指定的服务器列表上执行相同的命令,并查看每个服务器的执行结果。
在/root/bin目录下创建脚本xcall.sh
[root@hadoop102 bin]# vim xcall.sh
在脚本中编写如下内容
#! /bin/bash
for i in hadoop102 hadoop103 hadoop104
do
echo --------- $i ----------
ssh $i "$*"
done
修改脚本执行权限
[root@hadoop102 bin]# chmod 777 xcall.sh
启动脚本

340
568
419
261
342

被折叠的 条评论
为什么被折叠?