Solved

rsync with expect

Posted on 2002-07-29
8
1,933 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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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 500 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now