将文件从本地主机复制到多个远程主机的结构
问题描述:
我试图从我的本地结构系统将文件复制到使用fabric
put
put
命令的多个远程主机,所以,当我运行它时不会抱怨任何内容它不会复制文件。将文件从本地主机复制到多个远程主机的结构
其次,我看到我的远程服务器已经有文件,这可能是一个问题吗?在代码下面。
import sys
from fabric.api import env
from fabric.operations import run, put
env.skip_bad_hosts=True
env.command_timeout=160
env.user = 'jaggle'
env.shell = "/bin/sh -c"
env.warn_only = True
env.password = '[email protected]'
use_sudo = True
def readhost():
env.hosts = [line.strip() for line in sys.stdin.readlines()]
def copyLDAP():
put("/Karn/ldap.conf","/etc/ldap.conf", use_sudo = True)
下面是运行的输出...
$ echo "tt-server01" | fab readhost -f OpenDgCopy.py copyLDAP
[tt-server0] Executing task 'copyLDAP'
[tt-server0] put: /Karn/ldap.conf -> /etc/ldap.conf
Done.
Disconnecting from tt-server0... done.
答
取而代之的是readhost
任务的,可以直接使用-H
选项用逗号分隔的主机列表:
fab -f OpenDgCopy.py copyLDAP -H tt-server0,tt-sever1
根据put
的文档:
与OpenSSH
sftp
程序一样,.put
将在不请求确认的情况下覆盖 预先存在的远程文件。