Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

rsync with expect

Posted on 2002-07-29
8
Medium Priority
?
2,131 Views
Last Modified: 2008-03-17
I am using expect to anticipate a password prompt during an invocation of rsync over ssh. Unfortunately, expect prevents rsync from working properly in some way .. the rsync command has the desired effect when I run it directly, but when it is run by expect, it does nothing.

I am very new to expect, so please expect the mistake to be stupid.

Heres my expect script

#!/usr/bin/expect

set password [lindex $argv 0]


spawn rsync --recursive --rsh=ssh --size-only --archive --update --modify-window=900 --exclude='*.o' --exclude='*.ps' --exclude='*~' vil@libra1.rccp.tsukuba.ac.jp:/home/LATTICE/fellow/vil/gprogs/ /home/vil/gprogs

expect "vil@libra1.rccp.tsukuba.ac.jp's password:"
send "$password\r"
expect eof



spawn rsync --recursive --rsh=ssh --size-only --archive --modify-window=900 --exclude='*hosts*.static' --exclude='*~' vil@libra1.rccp.tsukuba.ac.jp:/home/LATTICE/fellow/vil/static/ /home/vil/static

expect "vil@libra1.rccp.tsukuba.ac.jp's password:"
send "$password\r"
expect eof


How do I need to modify this so that rsync commands work correctly under expect?

I asked this question previously but mistakenly accepted a wrong answer, so I am re-opening the thread. The previous discussion can be found at the link below, but please feel free to just dive in.

Thank you


http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=unix&qid=20326509
0
Comment
Question by:glebspy
8 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7187304
as said in the other question:
  first try to get ssh working with keys, then try it with rsync, and if then rsync fails we should talk about expect

Do you agree?
0
 
LVL 1

Author Comment

by:glebspy
ID: 7187316
Do you agree?

yes! totally. That is completely the logical order in which to proceed.

This is how far we got with ssh:

ahoffmann:
did you create new keys? did you install new keys on r
                       remote host? did you check for old/invalid keys?


glebspy:
                       yes, yes and yes.

                       There were some old keys in the remote authorized_keys file, but they were for other machines, so I guess I did the right thing in not deleting them.


 Maybe the superuser on the remote has activated some option which stops me from turning off the password prompt. If you have any ideas, or anything else for me to try, please say.
0
 
LVL 1

Author Comment

by:glebspy
ID: 7189739
For the benefit of anyone visiting this question, who does not want to trawl through the link to find out what ground has already been crossed, here is a summary:

It's generally agreed that the expect script is correct. So the question becomes, what is special about the rsync command (either something about the application itself, or the specific invocation) which causes it to fail when it is spawned from expect and the password is supplied. Also is the failure to do with the fact that it has been spawned from expect, or is the failure to do with the fact that we are trying to circumvent the password prompt. This question requires a theoretical solution.

There is also the possibility of a practical solution, which on expert has suggested, which is to try to stop rsync (in fact, ssh) even asking for a password prompt. So far this hasn't worked, although it's not clear why not .. the measures which one would naturally take to stop ssh asking for a password (making an rsa key and ftping it across) have been taken and yet the password prompt persists.

Hopefully this summary is useful to experts who are new to this question.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 38

Expert Comment

by:yuzh
ID: 7190009
Hi glebspy,

   Could you please post the information about which version of ssh you are running at both end.
0
 
LVL 1

Author Comment

by:glebspy
ID: 7190165
Sure, here's the output of `which ssh` -V

local:
[vil@localhost vil]$ `which ssh` -V
OpenSSH_3.0.2p1, SSH protocols 1.5/2.0, OpenSSL 0x0090602f

remote:
vil@libra1:~>`which ssh` -V
OpenSSH_3.1p1, SSH protocols 1.5/2.0, OpenSSL 0x0090602f
0
 
LVL 20

Accepted Solution

by:
Gns earned 2000 total points
ID: 7214580
Um, I think you might be a bit hasty in deeming the expect script sound.
You might need to set

timeout -1

before the spawn. It's been a while, but I think that sometimes you need this so that the expect statement doesn't timeout for "slow" spawned programs.
I usually try to use -re (regular expressions) "anchored" at either end of the input buffer, but that is surely a matter of taste.

-- Glenn
0
 
LVL 1

Author Comment

by:glebspy
ID: 7216174
My expect script is now:

#!/usr/bin/expect

set password [lindex $argv 0]


spawn rsync --recursive --rsh=ssh --size-only --archive --update --modify-window=900 --exclude='*.o' --exclude='*.ps' --exclude='*~' vil@libra1.rccp.tsukuba.ac.jp:/home/LATTICE/fellow/vil/gprogs/ /home/vil/gprogs

expect -timeout -1 "vil@libra1.rccp.tsukuba.ac.jp's password:"
send "$password\r"
expect -timeout -1 eof

and it works!

Congratulations on getting the right answer.
0
 
LVL 20

Expert Comment

by:Gns
ID: 7216454
Great that it works.

Once upon a time I wrote some fairly elaborate expect scripts (when does a script turn into a program? this was 2000+ lines of expect/tk code).
I found expect to be a great help, but at the same time ... "expecting" isn't always as straightforward as one would expect:-).
The timing issues, and (not) understanding how matching was done and on what (the anchoring part, which isn't to line ends, but rather to the buffer boundaries) had me running in pretty much the same circles you've been doing.
I then turned to open2 (in perl), which opened my eyes... There I could easily follow what was happening, but had to take care of the timing bit myself. The scripts (called from the Tk code) turned ugly fast. So it was back to expect and the solution of disabling timeouts.

Ah for the bygone days....;-)

-- Glenn
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question