脚本ssh进入其他主机报错--bash: jps: command not found和Error: JAVA_HOME is not set and java could not be found

一、报错图例

在这里插入图片描述

在这里插入图片描述

二、报错原因

原因:在shell脚本写的ssh到其他节点的时候默认是不加载配置文件的。linux并不能去找到java中jps的命令和java的path路径等。

三、解决方案(三种)

解决方案一:在ssh到其他节点的时候source一下配置文件。具体操作为:ssh $host“source /etc/profile:jps”

解决方案二:在ssh到其他节点的时候输入jps命令下的绝对路径。比如我的linux的jdk的绝对路径为: /opt/softs/jdk1.8.0/bin/,这个目录下就有jps的命令。具体操作为:ssh $host“/opt/softs/jdk1.8.0/bin//jps”

解决方案三:在当前用户的家目录中输入命令Il-a会显示隐藏文件,修改配置文件.bashrc。.bashrc是当你登入shel时执行在.bashrc里面加入source /etc/profile就行了。但是这种方法不推荐,容易出错

猜你喜欢

转载自blog.csdn.net/m0_48170265/article/details/131722478