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?
Yes, with ssh you can send commands directly to another system.
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
).
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
.
Another solution is to use the absolute path of ttisql
, then it will not depend on your PATH
setup.
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 $-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With