开发者

ssh executing commands remotely, how PATH is determined?

开发者 https://www.devze.com 2023-02-10 02:33 出处:网络
I have a bash script that uses ssh to execute commands remotely. I spotted however qu开发者_JAVA百科ite considerable difference in behaviour depending whether I launch commands in the background or no

I have a bash script that uses ssh to execute commands remotely. I spotted however qu开发者_JAVA百科ite considerable difference in behaviour depending whether I launch commands in the background or not:

ssh host cmd1 && cmd2 && cmd3

vs.

ssh host "cmd1 && cmd2 && cmd3" &

In the second case, some commands are not executed correctly because they don't appear on $PATH. It seems the environment is different in those two situations (when passing env as command I noticed quite considerable differences).

How to explain that ?

I know I could override PATH variable but is there a way to do it more in a elegant way to have the second example behave like first with "&" feature ?


In the first command you are probably executing cmd2 and cmd3 on the local host, not the remote one. The && words are interpreted by the local shell and not passed as arguments to ssh.


PATH is set while compiling sshd:

[~]> grep PATH /etc/sshd_config         
# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

Always use absolute paths while executing a remote command.

0

精彩评论

暂无评论...
验证码 换一张
取 消