【问题标题】:Python subprocess error: rsync error: syntax or usage error (code 1) at main.c(1407) [client=3.0.6]Python 子进程错误:rsync 错误:main.c(1407) [client=3.0.6] 处的语法或使用错误(代码 1)
【发布时间】:2020-09-03 08:47:31
【问题描述】:

我正在编写一个 Python 自动化脚本来通过 rsync 上传文件。从 Bash 运行它可以工作

/usr/bin/rsync -av -e “/usr/bin/ssh -i $PATH_TO_SSH_IDENTITY_KEY” $SRC USER@HOSTNAME:/firstparam/secondparam

但是,从 Python 运行会出现此错误

rsync error: syntax or usage error (code 1) at main.c(1407) [client=3.0.6]

这是调用 rsync 的代码

cmd = ['/usr/bin/rsync', '-av', '-e', config.ssh_identity, src, config.host + ':/rootpath' + firstparam + '/' + secondparam]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
(output, err) = p.communicate()

在哪里

config.ssh_identity = ‘/usr/bin/ssh -i $PATH_TO_SSH_IDENTITY_KEY’
config.host = ‘USER@HOSTNAME’

什么可能导致错误?

【问题讨论】:

  • 先尝试从os.environ获取PATH_TO_SSH_IDENTITY_KEY。
  • 您可能需要shell=False,因为您正在传递一个参数数组并且不希望它们中的任何一个被进一步分割为空格。

标签: python subprocess rsync


【解决方案1】:

想通了。根据Server Fault,我以超级用户身份运行脚本,但它不喜欢我不是我所说的那个人(ec2-user)。所以必须将超级用户关联为 ec2-user

【讨论】:

    猜你喜欢
    • 2017-10-03
    • 2016-01-08
    • 1970-01-01
    • 1970-01-01
    • 2016-01-17
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    相关资源
    最近更新 更多