#!/bin/bash
# 获取控制台指令
cmd=$*
# 判断指令是否为空
if [[ "$cmd" = "" ]]
then
echo "command can not be null !"
exit
fi
# 获取当前登录用户
user=`whoami`
# 在从机执行指令,这里需要根据你具体的集群情况配置,host与具体主机名一致
for (( host=1;host<=3;host++ ))
do
echo "================current host is hadoop$host================="
echo "--> excute command \"$cmd\""
ssh $user@hadoop$host $cmd
done
echo "excute successfully !"
[root@hadoop1 bin]# xcall.sh jps
================current host is hadoop1=================
--> excute command "jps"
12301 Jps
================current host is hadoop2=================
--> excute command "jps"
11856 Jps
================current host is hadoop3=================
--> excute command "jps"
11858 Jps
excute successfully !