通过SSH在远程服务器上执行命令 [英] Execute command on remote server via ssh

查看:570
本文介绍了通过SSH在远程服务器上执行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过本地服务器上的ssh命令在远程linux服务器上执行命令,如下所示:

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

ssh myremoteserver'键入ttisql'

ssh myremoteserver 'type ttisql'

ttisql是我的远程计算机路径上的可执行文件.

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

运行此命令的结果是:

bash:第0行:类型:ttisql:找不到

bash: line 0: type: ttisql: not found

当我简单地先连接并执行操作时:

When I simply connect first and do:

ssh myremoteserver

ssh myremoteserver

,然后输入命令:

[myuser @ myremoteserver〜] $:输入ttisql

[myuser@myremoteserver~]$: type ttisql

我按预期返回了ttisql exe的路径.

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

奇怪的是,当我在Beta环境中执行第一个命令时,它可以按预期工作并返回exe的路径.在测试版方案中,计算机A正在连接到远程计算机B,但是两台计算机都在现场,并且ssh命令可以快速连接到远程计算机.

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.

在我们的生产环境中,当机器A在本地并且机器B在现场并且ssh命令需要一两秒钟才能连接时,就会遇到问题.

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.

我能看到的唯一区别是生产ssh连接所花费的时间.远程系统上的路径是正确的,因为如果在初始连接之后输入命令,该命令将起作用.

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.

谁能帮助我理解为什么这个简单的命令会在一个环境中起作用而不在另一个环境中起作用?问题可能与通过ssh连接所花费的时间有关吗?

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?

推荐答案

您的PATH的设置在交互式shell(=在服务器上登录时)和非交互式(使用ssh).

Your PATH is setup differently when your shell is interactive (= when you are logged in on the server), and when not interactive (running commands with ssh).

查看外壳程序使用的rc文件,例如.bashrc.bash_profile.profile(取决于您的系统).如果将PATH设置在正确的位置,那么当通过ssh运行ttisql时,它可以工作.

Look into the rc files used by your shell, for example .bashrc, .bash_profile, .profile (depends on your system). If you set PATH at the right place, then ttisql can work when you run it via ssh.

另一种解决方案是使用ttisql的绝对路径,这将不取决于您的PATH设置.

Another solution is to use the absolute path of ttisql, then it will not depend on your PATH setup.

这篇关于通过SSH在远程服务器上执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆