Emmanuel Emmanuel - 2 months ago 10x
Python Question

fabric - is there a way to expand shell variables?

I'm trying to download a file from a remote host, with a remote path depending from a shell variable.

>>> with settings(host_string = 'user@server.com'):

It throws an error:

Fatal error: get() encountered an exception while downloading '/home/user/$ORACLE_HOME/network/admin/tnsnames.ora'

Underlying exception:
No such file

Is there a way to ask for shell variable expansion?


You can use fabric.operations.run():

from fabric.operations import run

oracle_path = run('echo $ORACLE_PATH', shell=True)

with settings(host_string = 'user@server.com'):
    get(os.path.join(oracle_path, 'network/admin/tnsnames.ora'))