运行 使用 python 的子进程使用带引号的参数进行 rsync
running rsync with quoted arguments using python's subprocess
我有一些使用 subprocess
模块执行 rsync
的自动化备份脚本。
一切都很好,直到指定 ssh 身份文件的新要求。
根据 rsync
手册,ssh 身份应作为带引号的字符串传递:
-e "ssh -i /home/username/.ssh/identity"
但这将无法在 subprocess
中 运行:
subprocess.Popen(['rsync', '-avz', '-e "ssh -i /home/username/.ssh/identity"', '~/Downloads', 'root@remote_server:/lvm/archive/backup'])
<subprocess.Popen object at 0x7fd111939710>
rsync: Failed to exec ssh -i /home/username/.ssh/identity: No such file or directory (2)
rsync error: error in IPC code (code 14) at pipe.c(85) [sender=3.1.0]
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in IPC code (code 14) at io.c(226) [sender=3.1.0]
有什么想法吗?
谢谢
subprocess.Popen(['rsync', '-avz', '-e', 'ssh -i /home/username/.ssh/identity', '~/Downloads', 'root@remove_server:/lvm/archive/backup'])
我有一些使用 subprocess
模块执行 rsync
的自动化备份脚本。
一切都很好,直到指定 ssh 身份文件的新要求。
根据 rsync
手册,ssh 身份应作为带引号的字符串传递:
-e "ssh -i /home/username/.ssh/identity"
但这将无法在 subprocess
中 运行:
subprocess.Popen(['rsync', '-avz', '-e "ssh -i /home/username/.ssh/identity"', '~/Downloads', 'root@remote_server:/lvm/archive/backup'])
<subprocess.Popen object at 0x7fd111939710>
rsync: Failed to exec ssh -i /home/username/.ssh/identity: No such file or directory (2)
rsync error: error in IPC code (code 14) at pipe.c(85) [sender=3.1.0]
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in IPC code (code 14) at io.c(226) [sender=3.1.0]
有什么想法吗?
谢谢
subprocess.Popen(['rsync', '-avz', '-e', 'ssh -i /home/username/.ssh/identity', '~/Downloads', 'root@remove_server:/lvm/archive/backup'])