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

[Expect] Reading from stdin

0 views
Skip to first unread message

Aquarius

unread,
Feb 23, 2000, 3:00:00 AM2/23/00
to
I'm attempting to write an Expect script to automate an ftp session. The
script receives on stdin:
a list of directories
a line saying "+++ Begin files +++"
a list of files

In theory, the script will eventually ftp these files to a remote server.
In practice, I haven't got that far yet, I just want the script to echo
them to stdout :)

So, I came up with this:

-------------begin partial script---------------
set onfiles 0
match_max 30000
for {} 1 {} {
expect_user ":-" {
# send directly to user
#send_user "$expect_out(buffer)"
} "+++ Begin files +++" {
set onfiles 1
#send_user "Transferring files\n"
} "+++ Begin directories +++" {
#send_user "Creating directories\n"
} "+++ End +++" {
send_user "End"
break
} -re "\n" {
if {0==$onfiles} {
send_user "Directory: mkdir $expect_out(buffer)"
} else {
send_user "File: put $expect_out(buffer)"
}
}
}
----------------end partial script--------------
The problem is this.
It gets fed quite a long list of directories and files (22 directories
and about 365 files, to be exact) on stdin. It gets part way through the
file list and then merrily stops processing further lines until it gets
to the stdin line "+++ End +++", where it prints "End", just as you'd expect.

I at first assumed that it was running out of space somewhere, so I tried
playing with match_max, but that didn't help. Presumably, though, if
there were out-of-space problems, it wouldn't find the end line. It seems
to get so far in the file list and then drop all the other names in the
bit bucket :(

Any help on why this happens would be deeply appreciated! :) The
scripting may be horribly bad Tcl or even vastly incorrect Tcl, which
might be my problem. I've cobbled it together by experimentation.

Aquarius

--
Tact is just not saying true stuff
-- Cordelia, "Buffy the Vampire Slayer"

schwa...@my-deja.com

unread,
Feb 23, 2000, 3:00:00 AM2/23/00
to
In article <88vddg$6nj$1...@kryogenix.yi.org>,


I think you might be trying to use Expect too much. Expect is a great
extension, but with any tool, it's best used for it's purpose.

I think you would do better using regular Tcl mechanisms to read the
data in, and then use Expect to carry out the ftp automation. Something
like:


-------------------------------8<-----------------------------------
set data [read stdin]

.
.
.
## parse through above data, maybe into arrays, lists, etc based
## on regexp matches, etc
.
.
.

spawn ftp 1.1.1.1
expect "ogin"
send "$user\r"
expect "assword"
send "$password\r"

foreach d $list_of_dirs {

foreach f $list_of_files($d) {

send "cd $d\r"
expect $prompt
send "put $f\r"
expect $prompt
}
}

--------------------------------8<---------------------------------

or something to that affect. Its the general idea...

--brett


Sent via Deja.com http://www.deja.com/
Before you buy.

Andreas Kupries

unread,
Feb 23, 2000, 3:00:00 AM2/23/00
to
Aquarius <aqua...@kryogenix.albatross.co.uk> writes:

> I'm attempting to write an Expect script to automate an ftp
> session. The

You might want to take a look at

http://home.t-online.de/home/Steffen.Traeger/tindexe.htm

too. This page provides the 'ftp_lib' by Steffen Traeger, an
implementation of FTP in pure tcl.

--
Sincerely,
Andreas Kupries <a.ku...@westend.com>
<http://www.purl.org/NET/akupries/>
-------------------------------------------------------------------------------

0 new messages