dcc310
dcc310

Reputation: 1076

Remote environment variable from file with Fabric

I am trying to just do a simple echo $MYVAR on a remote server with Fabric.

The environment variable is in my ~/.bashrc file on the remote host.

I have tried:

run("source /home/<myusername>/.bashrc && echo $MYVAR")

This just prints an empty string. Running it when logged in on the remote machine prints "5", the value in the bashrc file. Does anyone know why this would be?

I need the environment variable to be set from a file on the remote host, and not decided by Fabric.

I am running the ssh commands as <myusername>, so the username seems correct. This seems like a duplicate of this question, except that maybe they were running things as the wrong user. I also tried the shell argument to run, with no luck.

I haven't tried the various context manager-ish things, as they just seem to be a shorthand for command1 && command2.

Upvotes: 0

Views: 892

Answers (1)

kynan
kynan

Reputation: 13643

First, as explained in the answer you link to, fabric uses a login shell, not and interactive shell, meaning your ~/.bahsrc is not going to be source'd on the remote. You should export your variable in your ~/.bash_profile or ~/.profile.

Without the relevant content of your remote ~/.bashrc it's impossible to tell why your command fails.

Upvotes: 1

Related Questions