err: exit status 1
output: Missing trailing-' in remote-shell command.
rsync error: syntax or usage error (code 1) at main.c(432) [sender=3.1.2]
根据 man rsync 描述
-e, --rsh=COMMAND
This option allows you to choose an alternative remote shell program to use for com‐
munication between the local and remote copies of rsync. Typically, rsync is config‐
ured to use ssh by default, but you may prefer to use rsh on a local network.
If this option is used with [user@]host::module/path, then the remote shell COMMAND
will be used to run an rsync daemon on the remote host, and all data will be trans‐
mitted through that remote shell connection, rather than through a direct socket
connection to a running rsync daemon on the remote host. See the section "USING
RSYNC-DAEMON FEATURES VIA A REMOTE-SHELL CONNECTION" above.
Command-line arguments are permitted in COMMAND provided that COMMAND is presented
to rsync as a single argument. You must use spaces (not tabs or other whitespace)
to separate the command and args from each other, and you can use single- and/or
double-quotes to preserve spaces in an argument (but not backslashes). Note that
doubling a single-quote inside a single-quoted string gives you a single-quote;
likewise for double-quotes (though you need to pay attention to which quotes your
shell is parsing and which quotes rsync is parsing).
其中 Note that doubling a single-quote inside a single-quoted string gives you a single-quote 表示在单引号中重复单引号会得到一个单引号。
当使用 rsync 方式传输,-e 选项中有开始引号,而没有结束引号时,会报错。尤其是 ssh 密码比较复杂的情况下,比如
U6rOp>+d'z"NF7_P
。报错如下根据 man rsync 描述
其中 Note that doubling a single-quote inside a single-quoted string gives you a single-quote 表示在单引号中重复单引号会得到一个单引号。
rysnc 处理引号源码 https://github.com/RsyncProject/rsync/blob/4592aa770d51d5e83845b032feea1de441f03ee7/main.c#L528 测试用例
综上所述,处理逻辑应该把 rsync -e 选项中最大变数 ssh 密码用单引号括起来,然后转义其中的单引号(重复单引号)即可。