Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
511 views
in Technique[技术] by (71.8m points)

linux - Execute command on remote server via ssh

I am attempting to execute a command on a remote linux server via an ssh command on a local server like this:

ssh myremoteserver 'type ttisql'

where ttisql is an executable on the path of my remote machine.

The result of running this is:

bash: line 0: type: ttisql: not found

When I simply connect first and do:

ssh myremoteserver

and then enter the command:

[myuser@myremoteserver~]$: type ttisql

I get back the path of the ttisql exe as I would expect.

The odd thing is that when I execute the first command in my beta environment it works as expected and returns the path of the exe. In the beta scenario, machine A is connecting to remote machine B but both machines are onsite and the ssh command connects to the remote machine quickly.

The problem is encountered in our production environment when machine A is local and machine B is offsite and the ssh command takes a second or two to connect.

The only difference I can see is the time it takes the production ssh to connect. The path on the remote system is correct since the command works if entered after the initial connection.

Can anyone help me understand why this simple command would work in one environment and not the other? Could the problem be related to the time it takes to connect via ssh?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The environment can be different in a non-interactive session (ssh command) from an interactive session (ssh, then command). Try echo $PATH in both cases.

ssh myremoteserver 'echo $PATH'

vs

ssh myremoteserver
[myuser@myremoteserver~]$: echo $PATH

If they differ, look in all startup script for some differentiated behavior based on $PS1 or $-


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...