Below is my code:

#!/usr/bin/expect -f
set timeout -1
spawn rsync -arvz -e 'ssh -p 1690' --protect-args --progress /home/pappu/ '[email protected]:/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/ '[email protected]:/volume1/56 - Backup Server/pappu'
Unexpected remote arg: '[email protected]:/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. Jun 29, 2016 at 15:09
  • 1
    Did you mean xxxxxx\r by any chance? Jun 29, 2016 at 15:54
  • @steeldriver : thanks, I mis typed while typing/formatting here in questions Jun 30, 2016 at 6:08
  • @roaima, user [email protected] doesn't have a home directory, I'm not aware with ssh key without home directory. Jun 30, 2016 at 6:10

1 Answer 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/ "[email protected]:/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 Jun 30, 2016 at 7:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .