So I'm trying to do something that involves running sbt
over an SSH command, and this is what I'm trying:
ssh my_username@<server ip> "cd <project folder>; sbt 'run-main Foo' "
When I do that however, I get an error message: bash: sbt: command not found
Then I go SSH into the server myself, cd
to the project folder, and run sbt 'run-main Foo'
and everything works nicely. I have checked to make sure sbt
is on the $PATH
variable on the remote server via ssh my_username@<server ip> "echo $PATH"
and it shows the correct value.
I feel like this is a simple fix, but cannot figure it out... help?
Thanks!
-kstruct
When you log in, bash
is run as an interactive shell. When you run commands directly through ssh
, bash is run as a non-interactive shell, and therefore different initialization files are sourced (see the bash manual pages for which exactly). There are a number of ways to fix this, e.g.:
- Use the full path to
sbt
when calling it directly through ssh
- Edit
.bashrc
and add the missing directories to the PATH
environment variable
Note that your test ssh my_username@<server ip> "echo $PATH"
actually prints PATH
on your client, not your server, because of the double quotes. Use ssh my_username@<server ip> 'echo $PATH'
or ssh my_username@<server ip> env
to print PATH
from the server's environment. When checking using env
, you will see that PS1
is only set in interactive shells.