我正在尝试从远程主机下载文件,其远程路径取决于shell变量。
>>> with settings(host_string = 'user@server.com'):
get('$ORACLE_HOME/network/admin/tnsnames.ora')
它会抛出错误:
Fatal error: get() encountered an exception while downloading '/home/user/$ORACLE_HOME/network/admin/tnsnames.ora'
Underlying exception:
No such file
有没有办法要求shell变量扩展?
答案 0 :(得分:1)
您可以使用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'))