xcall脚本
通过编写的xcall脚本, 能够在一台主机上执行其它主机上的命名令.具体脚本编写如下:
#!/bin/bash
# 验证参数
if(($#==0))
then
echo 请输入要执行的命令!
exit
fi
echo "要执行的命令是:$@"
# User specific aliases and functions
source /etc/profile
# 批量执行
for((i=2;i<=3;i++))
do
echo ------------------node0$i------------------
ssh node0$i $@
done
解决无法执行xcall jps的第二种方案
当通过以上脚本执行xcall jps时, 却出现无法找到jps的情况. 有种方式是在usr/local/bin下创建jps的软连接. 但明明已经在/etc/profile中将jps命令所在目录添加到了PATH为什么会出现未找到命令的情况. 这就需要知道一点, xcall脚本本质上是通过ssh来执行命令的, 而ssh分为两类: "Login Shell"与"Non-Login shell"两类, 而"Nod-Login shell"引入了~/.bashrc, 但是没有引入/etc/profile. 所以需要在目的主机的相应家目录下编辑文件~/.bashrc, 在该文件中追加以下语句即可:
source /etc/profile
参考:
https://www.cnblogs.com/qixing/p/11430867.html