我正在运行这段代码来检查远程机器上是否存在这个目录,但这段代码正在检查本地机器上的目录。如何验证远程机器上的目录?
rom fabric.api import run, sudo, env
import os
env.hosts = ['remote_server']
env.user = 'ubuntu'
env.key_filename = '/home/ubuntu/ubuntu16-multi.pem'
def Directory_Check():
DIR_1="/home/ubuntu/test-dir"
if os.path.exists(DIR_1):
print "Directory Exist!"
else:
print "Directory Does Not Exist!"
最佳答案
虽然接受的答案对 fabric ver 1 有效,但对于在寻找相同内容但 fabric2 时点击此线程的任何人:
fabric.contrib.files
中的 exists
方法已移至 patchwork.files
并进行了小的签名更改,因此您可以像这样使用它这个:
from fabric2 import Connection
from patchwork.files import exists
conn = Connection('host')
if exists(conn, SOME_REMOTE_DIR):
do_something()
关于python - 使用 Fabric 检查路径是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44736637/