Altough Fabric 文档是指一种使用库进行 SSH 访问而不需要 fab 命令行工具和/或任务的方法,我似乎无法管理这样做的方法。
我想通过只执行'python example.py'来运行这个文件(example.py):
env.hosts = [ "example.com" ]
def ps():
run("ps")
ps()
谢谢。
最佳答案
我最终这样做了:
from fabric.api import env
from fabric.api import run
class FabricSupport:
def __init__ (self):
pass
def run(self, host, port, command):
env.host_string = "%s:%s" % (host, port)
run(command)
myfab = FabricSupport()
myfab.run('example.com', 22, 'uname')
产生:
[example.com:22] run: uname
[example.com:22] out: Linux
关于python - 在没有命令行工具 (fab) 的情况下使用 Python Fabric,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6741523/