expectでrsyncがエラーになる場合の対処法について紹介します。
2年前から放置してたけどちょっと調べたら解決できました。(英語読めないときついと思われ)
こういうエラーがでる。
Missing trailing-' in remote-shell command.
rsync error: syntax or usage error (code 1) at main.c(430) [sender=3.1.1]
コードは以下。
#!/usr/bin/expect -f
# exp_internal 1 ;# uncomment to turn on expect debugging
set timeout -1
spawn rsync -av -e 'ssh -p 10022 -i ~/.ssh/yuis.key' hoge.md yuis@sv2031.xserver.jp:~/yuis.xsrv.jp/public_html/_tmp
expect "Enter passphrase"
send "yourownpassword\n"
expect eof
原因
シングルクォーテーション。
ssh – rsync complaining about missing trailing-"
in a Bash script – Super User
解決法
シングルクォーテーションをダブルクォーテーションに変更する
これでいけます。
#!/usr/bin/expect -f
# exp_internal 1 ;# uncomment to turn on expect debugging
set timeout -1
spawn rsync -av -e "ssh -p 10022 -i ~/.ssh/yuis.key" hoge.md yuis@sv2031.xserver.jp:~/yuis.xsrv.jp/public_html/_tmp
expect "Enter passphrase"
send "yourownpassword\n"
expect eof