Shell-Script

期望帶雙引號的 Rsync

  • March 9, 2019

下面是我的程式碼:

#!/usr/bin/expect -f
set timeout -1
spawn rsync -arvz -e 'ssh -p 1690' --protect-args --progress /home/pappu/ 'backup@xx.xx.xx.xx:/volume1/56 - Backup Server/pappu'
expect "password:"
send "******/r"
expect eof

腳本有+x權限,我正在執行它,如下所示:

~]# ./rsync-backup.sh

它給了我以下輸出:

spawn rsync -arvz -e 'ssh -p 1690' --protect-args --progress /home/pappu/ 'backup@xx.xx.xx.xx:/volume1/56 - Backup Server/pappu'
Unexpected remote arg: 'backup@xx.xx.xx.xx:/volume1/56
rsync error: syntax or usage error (code 1) at main.c(1201) [sender=3.0.6]
send: spawn id exp4 not open
     while executing
"send xxxxxx/r"
     (file "./rsync-backup.sh" line 5)

我嘗試在 rsync 的遠端路徑中添加雙引號,還嘗試在單引號和雙引號中添加斜線。(它只是更改錯誤消息)。

expect是用該tcl語言編寫的,因此包含空格的字元串必須用雙引號"而不是單引號引起來'。所以用

spawn rsync -arvz -e "ssh -p 1690" --protect-args --progress /home/pappu/ "backup@xx.xx.xx.xx:/volume1/56 - Backup Server/pappu"

另外,正如@steeldriver 所提到的,寫了一個輸入\r,所以你可能想要

send "******\r"

引用自:https://unix.stackexchange.com/questions/292888