0

Below is my code:

#!/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

script has +x permission, and I'm executing it as below:

~]# ./rsync-backup.sh

It gives me below output:

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)

I tried adding double quotes in remote path of rsync, also tried adding slash with single and double quote. (It just changes the error message).

  • 3
    Any reason why you can't use ssh certificate-based authentication, and avoid the need for a password entirely? You could then also dispense with expect. – roaima Jun 29 '16 at 15:09
  • 1
    Did you mean xxxxxx\r by any chance? – steeldriver Jun 29 '16 at 15:54
  • @steeldriver : thanks, I mis typed while typing/formatting here in questions – Ravi Jun 30 '16 at 6:08
  • @roaima, user backup@xx.xx.xx.xx doesn't have a home directory, I'm not aware with ssh key without home directory. – Ravi Jun 30 '16 at 6:10
1

expect is written in the tcl language, so strings containing whitespace must be quoted with double-quotes " not single quotes '. So replace your spawn line with

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

Also, as mentioned by @steeldriver, a carriage-return is written \r, so you probably want

send "******\r"
  • Thank you @meuh, It is working now, I'll read more about tcl so not stuck on silly things, thanks again for your help – Ravi Jun 30 '16 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.