Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

expect: automating scp

645 views
Skip to first unread message

Michael P. Soulier

unread,
May 31, 2002, 12:43:11 PM5/31/02
to
Hey people,

So I have this expect script that's worked fine for some time, but all of
a sudden it's quitting early on an scp file transfer when it used to wait
until completion. Here's the relevant procedure.

proc scp {tarball} {
global host user password directory

set scp "/usr/bin/scp"

if {! [file exists $tarball]} {
puts stderr "ERROR: $tarball does not exist."
exit 1
}

set timeout 60
puts "Copying tarball to sourceforge..."
spawn scp $tarball $user@$host:$directory
expect "password:" {
send "$password\r"
expect " 100% "
}
}

By expecting 100%, it's always picked up the progress reading, and moved
on when the scp was finished. Now it's stopping when the output reads...

opag.tar.gz 36% |********** | 952 KB 01:42
ETA

I don't see why it would stop here, but it's completely reproducable.

Any help appreciated,

Thanks,

Mike

--
Michael P. Soulier <msou...@storm.ca>, GnuPG pub key: 5BC8BE08
"...the word HACK is used as a verb to indicate a massive amount
of nerd-like effort." -Harley Hahn, A Student's Guide to Unix

Glenn Jackman

unread,
May 31, 2002, 1:33:40 PM5/31/02
to
On 31 May 2002 16:43:11 GMT, Michael P. Soulier
<msou...@mcss.mcmaster.ca_.nospam> wrote:
> So I have this expect script that's worked fine for some time, but all of
>a sudden it's quitting early on an scp file transfer when it used to wait
>until completion. Here's the relevant procedure.
[...]

> spawn scp $tarball $user@$host:$directory

Should this be: spawn $scp ... , since you set that variable earlier?

[...]


> I don't see why it would stop here, but it's completely reproducable.

Is it reproducable only from the expect script, or from the command line too?

--
Glenn Jackman
gle...@ncf.ca

Roland Roberts

unread,
May 31, 2002, 3:32:56 PM5/31/02
to
>>>>> "Michael" == Michael P Soulier <msou...@mcss.mcmaster.ca_.nospam> writes:

Michael> spawn scp $tarball $user@$host:$directory
Michael> expect "password:" {
Michael> send "$password\r"
Michael> expect " 100% "
Michael> }

Michael> By expecting 100%, it's always picked up the progress
Michael> reading, and moved on when the scp was finished. Now it's
Michael> stopping when the output reads...

Michael> opag.tar.gz 36% |********** | 952 KB 01:42
Michael> ETA

Michael> I don't see why it would stop here, but it's completely
Michael> reproducable.

I don't have a good answer for you, but whenever I have tried to
automate something which may be sending escape sequences to the
screen, I've tried to find a way to use interact.

I tried running autoexpect with something like the above scp command
(except I usually have ssh-agent running in the background). It
appears that scp is printing the entire line and doesn't get a newline
until the copy is completely finished. If that's the case, then
something like this might do the trick for you

spawn scp $tarball $user@$host:$directory
expect "password:" {
send "$password\r"

interact "\n"
}

or possibly try the -nobuffer option to interact

spawn scp $tarball $user@$host:$directory
expect "password:" {
send "$password\r"

interact -nobuffer "\n"
}

roland
--
PGP Key ID: 66 BC 3B CD
Roland B. Roberts, PhD RL Enterprises
rol...@rlenter.com 76-15 113th Street, Apt 3B
rol...@astrofoto.org Forest Hills, NY 11375

Don Libes

unread,
Jun 1, 2002, 6:13:51 PM6/1/02
to

Perhaps it's hitting your self-imposed 60 second timeout?

Don

Michael P. Soulier

unread,
Jun 1, 2002, 10:35:40 PM6/1/02
to
On 01 Jun 2002 18:13:51 -0400, Don Libes <li...@nist.gov> wrote:
>
> Perhaps it's hitting your self-imposed 60 second timeout?

Y'know, I forgot I even did that. I'll bet that's what it is...

Thanks, I'll go get a coffee now. ;-)

0 new messages