Solve the problem related to 'COMMAND not found' in ssh user @ ip' command '.
Environment centos6.5
Status A machine ssh user @ B machine 'command' command to execute the command(Machine B adds trust in machine)
Prompt'bash: node: command not found'
UseSsh user @ B Machine
It is no problem to manually execute the command.echo $PATH;node -v
It is also normal
-Bash-4.1 $ ssh root @ machine B IPLast login: Sat Jun 18 15:14:35 2016 from machine A IP Address [root @ IOS-Account ~] # Echo $ PATH; node-v/data/soft/node/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin: /usr/sbin:/usr/bin:/sbin:/root/binv4.4.4
UseSsh user @ B machine 'echo $ PATH; node-V'
The printed environment variable path is different from the printed path in login mode.
-Bash-4.1 $ ssh root @ B server IP 'echo $ PATH; node-V'/usr/local/sbin:/usr/local/bin:/sbin:/bin: /usr/sbin:/usr/bin:/sbinbash: node: command not found
According to this article, the cause is found. The environment variables of the following two logon methods are different.ssh user@ip
There will be interactions after loginssh user@ip 'command'
After logging on, run the command and exit.
Finally, my solution is:
Ssh root @ B server IP address 'source ~ /. Bash_profile; echo $ PATH; node-v'
Result:
-Bash-4.1 $ ssh root @ machine B IP address 'source ~ /. Bash_profile; echo $ PATH; node-v '/data/soft/node/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin: /usr/sbin:/usr/bin:/sbin:/root/binv4.4.4