I am writing a bash
shell script that I can run on my local computer to update and redeploy a simple app hosted on an AWS E2 instance. I am having trouble with one line in particular: I cannot seem to activate a conda
environment within the ssh
command.
ssh -i $private_key_file $public_dns "conda activate ENVIRONMENT_NAME"
Returns:
bash: line 1: conda: command not found
However, if I ssh in with ssh -i $private_key_file $public_dns
and then run conda activate ENVIRONMENT_NAME
separatly this works fine.
What is happening? All other commands in my shell script are working fine with the ssh -i $private_key_file $public_dns "COMMAND"
syntax.
My instance is running Ubuntu 22.04 if relevant.
2
Answers
After some more searching, I found my
.bashrc
file contained the following lines:I solved this problem by simply moving my
conda
block above this line. I found this from the "community wiki"-owned response to this question.What I tried:
.bashrc
file prior to runningconda activate ENVIRONMENT_NAME
. This did not solve the issue, apparently because it was still leaving the script on my non-interactive session..bashrc
in a.bash_profile
file, which is recommended as another top answer in the thread linked above. While this does work in sourcing.bashrc
, it still exists at the non-interactive condition.Because the
conda
command is not found in the path.Plausible.
Your
conda
command is not present in the system’s default path. Likely you have installed a personal copy rather than a system-wide copy. Your personal shell setup scripts,.bash_profile
and / or.bashrc
prepare your interactive shells to run theconda
command, but these are not read when you launch a shell non-interactively, asssh
does on your behalf in the first example.You could do something like
, but I don’t see the point, because the shell in which you activate
conda
terminates immediately afterward, mooting the whole exercise. Whatever it is you want to run in your conda environment, consider writing a wrapper script on the E2 side that takes care of running it in the right environment.