Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to use expect to handle rsync over an ssh shell, but it gets stuck.

If I run my rsync command it works (simplified here): It prompts me for my password and copies files to the server:

rsync -e ssh -<other_params>

If I then enclose that in expect:

expect -d -c "spawn rsync -e ssh -<other_params>" -c "expect password:" -c "send mypass\r"

It does not execute properly, the program exists and no files are copied. Even the debug mode isn't giving many clues.

My best guess is that rsync is spawning the ssh process, and the ssh process is what needs to be interacted with, but send is picking up the rsync process id and sending the input there.

Any thoughts?

share|improve this question
1  
Can you set up your ssh for public-key/password-less login? Then you can dispense with expect. IF not, try spawning the subprocess with a pty rather than a pipe (if that's what it's doing). –  Keith Jun 27 '11 at 9:08

1 Answer 1

up vote 0 down vote accepted

The answer to this issue was that I needed to add a wait command at the end of the expect script. As it is shown in the question, it was working, but it was sending the password and then immediately killing the process. Adding wait waits for the rsync process to complete.

Corrected version:

expect -d -c "spawn rsync -e ssh -<other_params>" -c "expect password:" -c "send mypass\r" -c "wait"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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