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,
bashis run as an interactive shell. When you run commands directly throughssh, 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.:sbtwhen calling it directly throughssh.bashrcand add the missing directories to thePATHenvironment variableNote that your test
ssh my_username@<server ip> "echo $PATH"actually printsPATHon your client, not your server, because of the double quotes. Usessh my_username@<server ip> 'echo $PATH'orssh my_username@<server ip> envto printPATHfrom the server’s environment. When checking usingenv, you will see thatPS1is only set in interactive shells.