首页 > 其他分享 >执行ssh $host jps 报错:“bash: jps: 未找到命令”

执行ssh $host jps 报错:“bash: jps: 未找到命令”

时间:2022-10-06 16:25:42浏览次数:91  
标签:bin host 未找到 报错 ssh jps bash

学习Hadoop,想写个脚本查看集群各节点的运行情况:

#!/bin/bash
for host in hadoop1 hadoop2 hadoop3
do
	echo ==================== $host ====================
	ssh $host $JAVA_HOME/bin/jps
done

执行后报错:

==================== hadoop1 ====================
bash: jps: 未找到命令
==================== hadoop2 ====================
bash: jps: 未找到命令
==================== hadoop3 ====================
bash: jps: 未找到命令

 
原因:
参考别人的博客了解到:通过SSH远程执行命令和脚本不会加载/etc/profile文件,而会去用户的HOME目录检查.bashrc并加载,所以得不到环境。
 
解决方法:
1 直接写绝对路径

#!/bin/bash
for host in hadoop1 hadoop2 hadoop3
do
	echo ==================== $host ====================
	ssh $host $JAVA_HOME/bin/jps
done

2 在用户的~/.bashrc里增加Java路径(采用了第一种方式,第二种未试过)
 
 
参考自:https://blog.csdn.net/weixin_45772874/article/details/121270823

标签:bin,host,未找到,报错,ssh,jps,bash
From: https://www.cnblogs.com/lgjb/p/16757791.html

相关文章