The script ssh enters other hosts and reports errors --bash: jps: command not found and Error: JAVA_HOME is not set and java could not be found

1. Error report legend

insert image description here

insert image description here

2. The reason for the error

reason:When the shell script writes ssh to other nodes, the configuration file is not loaded by default. Linux cannot find the jps command in java and the path path of java.

3. Solutions (three types)

Solution 1: Source the configuration file when ssh to other nodes. The specific operation is: ssh $host "source /etc/profile:jps"

Solution 2: Enter the absolute path under the jps command when ssh to other nodes. For example, the absolute path of my linux jdk is: /opt/softs/jdk1.8.0/bin/, there is a jps command in this directory. The specific operation is: ssh $host "/opt/softs/jdk1.8.0/bin//jps"

Solution 3: Enter the command Il-a in the current user's home directory to display hidden files and modify the configuration file .bashrc. .bashrc is executed when you log in to the shell. Just add source /etc/profile to .bashrc. But this method is not recommended, it is error-prone

Guess you like

Origin blog.csdn.net/m0_48170265/article/details/131722478