4

I'm trying to run a command that I've installed in my home directory on a remote server. It's already been added to my $PATH in .bash_profile. I'm able to use it when logged in remotely via a normal ssh session, but Fabric doesn't seem to be pulling in my $PATH. Thus, I've tried adding it to my $PATH using Fabric's path context manager like so:

def test_path():
    print('My env.path setting: %(path)s' % env)
    with path('/path/to/sources/drush'):
        run('echo $PATH')
        run('drush')

Fabric responds with:

Executing task 'test_path'
My env.path setting:
run: echo $PATH
out: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
out:

run: echo $PATH
out: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/path/to/sources/drush
out:

run: drush
out: /bin/bash: drush: command not found
out:

Fatal error: run() received nonzero return code 127 while executing!

Requested: drush
Executed: /bin/bash -l -c "export PATH=\"\$PATH:\"/path/to/sources/drush\" \" && drush"

Aborting.

Thanks for looking...

4
  • what's your PATH setting when you actually login to the remote server?
    – isedev
    Mar 20, 2013 at 20:25
  • do you have anything in env.path?
    – alecxe
    Mar 20, 2013 at 20:49
  • @isedev When logging in via a normal ssh session, this is my path /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/path/to/sources/drush
    – user981023
    Mar 21, 2013 at 11:36
  • @AlexanderAfanasiev I haven't explicitly set anything in env.path. I've updated the original post and added this print statement: print('My env.path setting: %(path)s' % env), which shows the env.path is empty.
    – user981023
    Mar 21, 2013 at 11:57

1 Answer 1

2

The problem is in the way the PATH variable gets set - there is an additional space character at the end of it:

/bin/bash -l -c "export PATH=\"\$PATH:\"/path/to/sources/drush\" \" && drush"
                                                                ^HERE

The last directory in the search path is interpreted by bash as "/path/to/source/drush " (trailing space) - an invalid directory.

2
  • How do I prevent it from adding the space? There's no space between "drush" and my quote character in the with statement.
    – user981023
    Mar 21, 2013 at 12:01
  • The source code for the path context manager for Fabric contains the following comment: "Any calls to run or sudo within the wrapped block will implicitly have a string similar to "PATH=$PATH:<path> " prepended before the given command.". So this behaviour seems to be by design. You should contact the developers and report this, find out why they do it like this and whether it's a bug or a feature. Here's the mailing list
    – isedev
    Mar 21, 2013 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.