expect and expecting it this way or this way...?

expect and expecting it this way or this way...?

Post by L Hradow » Thu, 17 Apr 2003 12:07:31



I am logging into numerous switches, it so happens that there are a few
different versions of the way the data is presented back on log in. How do I
take into consideration with expect about this.

One way is ...
Telnet LINEMODE.

 Enter User Name
MIB variable CharOptionAllowed must be set first to allow CHAR MODE.

The other way is ...
Telnet LINEMODE.
MIB variable CharOptionAllowed must be set first to allow CHAR MODE.

Enter User Name

My expect script was doing...
expect {
"Enter User Name\r

Quote:>"

Also how would I write an expect after I log in, it sends me data and the
last line before the prompt is returned to me is ...
2003/03/12 23:06  data... MAR/11/2003 ***

(this is different on various ones, sometimes the date is different,
sometimes there are spaces after the three *** and then the /r, sometimes
there are no spaces after the ***, then the /r

My expect was
expect {
"200? *** \r

Quote:>$"

Now this works on a few, but how do incorporate all the different versions.

Would really appreciate all your help...
Laura

 
 
 

expect and expecting it this way or this way...?

Post by Cameron Lai » Fri, 18 Apr 2003 01:26:10




>I am logging into numerous switches, it so happens that there are a few
>different versions of the way the data is presented back on log in. How do I
>take into consideration with expect about this.

>One way is ...

                        .
                        .
                        .
I'll start with a few general comments.  Perhaps
one of us will make time to address the specific
technical difficulties you raise, later this week.

First, get the book.  You'll be glad you do.  Expect
is absolutely the right technology to use for these
situations, and you'll be quite pleased with it once
you are more familiar with it.  The challenges you
describe are exactly those Expect's equipped to ad-
dress.  Moreover, the book is an enormous help.  Get
the book.

It frequently is OK to start a bit "sloppy"; you
don't have to emphasize exact matches in your Expect
coding.  Write brief patterns that distinguish the
last few unique characters of response.
--


Business:  http://www.Phaseit.net
Personal:  http://phaseit.net/claird/home.html

 
 
 

expect and expecting it this way or this way...?

Post by Kenny McCorma » Fri, 18 Apr 2003 02:30:39



...

Quote:>It frequently is OK to start a bit "sloppy"; you
>don't have to emphasize exact matches in your Expect
>coding.  Write brief patterns that distinguish the
>last few unique characters of response.

I think people get started on the idea of using exact matches because they
use "autoexpect" as a starting point.  Autoexpect generates code with all
the matches exact.  In general, autoexpect generates code very unlike what
you would get writing by hand.

General comment: Most scripting languages eventually evolve to the point of
providing a tool to write the code for you (e.g., Expect, Winbatch).
Unfortunately, these tools generate code very unlike regular, human-written
code, and the result is that people who learn to use these tools never
really learn the underlying language.  Pity.

P.S.  I myself do use autoexpect sometimes as a basis for writing a brand
new script - but I usually totally gut its output - in the process of
converting it to a regular script.

 
 
 

expect and expecting it this way or this way...?

Post by Lincoln Ramsa » Fri, 18 Apr 2003 07:12:43


At around 16/04/2003 1:07pm, L Hradowy declared:

Quote:> Also how would I write an expect after I log in, it sends me data and the
> last line before the prompt is returned to me is ...
> 2003/03/12 23:06  data... MAR/11/2003 ***

A regular expression will probably help. You'll need to identify definite start
and end points for your RE though. Remember that expect's REs aren't line
oriented like perl, grep, etc.

The following matches a newline, some non-newline chars and three * chars then
sends it (without the first newline) to the user.

expect -re "\n(\[^\n\]*\*\*\*)" {
        send_user "$expect_out(1,string)\n"

Quote:}

--
Send email to ramsayl at bigfoot dot com            \|/
.                                                  (- -)
+----------------------------------------------ooO--(_)--Ooo--+
| There is no emotion, there is peace. There is no ignorance, |
| there is knowledge. There is no passion, there is serenity. |
| There is no death, there is the force.    -- Jedi Code      |
+-------------------------------------------------------------+
 
 
 

expect and expecting it this way or this way...?

Post by Don Libe » Fri, 18 Apr 2003 23:56:33





> ...
> >It frequently is OK to start a bit "sloppy"; you
> >don't have to emphasize exact matches in your Expect
> >coding.  Write brief patterns that distinguish the
> >last few unique characters of response.

> I think people get started on the idea of using exact matches because they
> use "autoexpect" as a starting point.  Autoexpect generates code with all
> the matches exact.  In general, autoexpect generates code very unlike what
> you would get writing by hand.

> General comment: Most scripting languages eventually evolve to the point of
> providing a tool to write the code for you (e.g., Expect, Winbatch).
> Unfortunately, these tools generate code very unlike regular, human-written
> code, and the result is that people who learn to use these tools never
> really learn the underlying language.  Pity.

> P.S.  I myself do use autoexpect sometimes as a basis for writing a brand
> new script - but I usually totally gut its output - in the process of
> converting it to a regular script.

Good observations.  There's also a paper on autoexpect that talks
about these issues and some others that you might find interesting.

http://expect.nist.gov/doc/autoexpect.pdf

Don

 
 
 

expect and expecting it this way or this way...?

Post by Cameron Lai » Sat, 19 Apr 2003 02:26:33




>I am logging into numerous switches, it so happens that there are a few
>different versions of the way the data is presented back on log in. How do I
>take into consideration with expect about this.

                        .
                        .
                        .
Ms. Hradowy, it appears none of us will immediately have an
opportunity to work through your question as you originally
proposed it.  Perhaps you will want to provide more detail
<URL: http://wiki.tcl.tk/RequestHelp > that will encourage
us to focus attention efficiently:  do you have a copy of
the book?  Are you an autoexpect user?

Maybe it'll work best to begin with just one issue.  Can
you write two simple scripts that each exercise a target
system up to the first point that the two systems diverge?
If you supply us with a minimal such form, we probably can
demonstrate quickly how to consolidate the two separate
scripts.
--


Business:  http://www.Phaseit.net
Personal:  http://phaseit.net/claird/home.html

 
 
 

expect and expecting it this way or this way...?

Post by Chang L » Sat, 19 Apr 2003 12:47:07




> Good observations.  There's also a paper on autoexpect that talks
> about these issues and some others that you might find interesting.

> http://expect.nist.gov/doc/autoexpect.pdf

> Don

Is it possible to use autoexpect without interact inside?

Chang

 
 
 

expect and expecting it this way or this way...?

Post by Cameron Lai » Sun, 20 Apr 2003 02:16:24



                        .
                        .
                        .
Quote:>Is it possible to use autoexpect without interact inside?

                        .
                        .
                        .
I don't understand the question.  The standard distribution
source for autoexpect does exploit [interact].  Are you ask-
ing that someone rewrite autoexpect so that it doesn't use
[interact]?  Are you trying to achieve an autoexpect that
works with Gordon Chafee's Expect-for-Windows?
--


Business:  http://www.Phaseit.net
Personal:  http://phaseit.net/claird/home.html

 
 
 

expect and expecting it this way or this way...?

Post by Chang L » Sun, 20 Apr 2003 08:55:30





> .
> >Is it possible to use autoexpect without interact inside?
> .
> I don't understand the question.  The standard distribution
> source for autoexpect does exploit [interact].  Are you ask-
> ing that someone rewrite autoexpect so that it doesn't use
> [interact]?  Are you trying to achieve an autoexpect that
> works with Gordon Chafee's Expect-for-Windows?

Try to use it on windows but there is no interact available.
But I think interact is the simplest solution.

I tested the autoexpect in Cygwin with "autoexpect ftp ftp.corp.com"
After typing the first character of the Password, the program said
login failed. Is it a bug?

Chang

> --


> Business:  http://www.Phaseit.net
> Personal:  http://phaseit.net/claird/home.html

 
 
 

expect and expecting it this way or this way...?

Post by Cameron Lai » Tue, 22 Apr 2003 11:41:08



                        .
                        .
                        .
Quote:>Try to use it on windows but there is no interact available.
>But I think interact is the simplest solution.

>I tested the autoexpect in Cygwin with "autoexpect ftp ftp.corp.com"
>After typing the first character of the Password, the program said
>login failed. Is it a bug?

                        .
                        .
                        .
autoexpect as distributed does not work with the Gordon
Chaffee Expect-for-Windows because, as you've noted, it
relies on [interact], and that's never been available for
Windows.  I'll speculate that autoexpect's dependence is
fundamental, that is, that a full autoexpect coded without
[interact] essentially replicates [interact]'s function-
ality.  Don and Davy should know better than I, though.

The Cygwin behavior you describe sounds like an error.  I'm
not current on Cygwin; I have no idea why this is happen-
ing.  My guess is that Don will want to know about and
correct it.

If your immediate requirement is to automate FTP client
operation from a Win* host, I have strong beliefs that
there are more productive ways to go about it.  Are you
using an ftp capability not available through tcllib's
ftp package?  That's where I'd start *my* coding.
--


Business:  http://www.Phaseit.net
Personal:  http://phaseit.net/claird/home.html

 
 
 

expect and expecting it this way or this way...?

Post by Don Libe » Tue, 22 Apr 2003 11:59:52





> >Try to use it on windows but there is no interact available.
> >But I think interact is the simplest solution.

> >I tested the autoexpect in Cygwin with "autoexpect ftp ftp.corp.com"
> >After typing the first character of the Password, the program said
> >login failed. Is it a bug?
>                    .
>                    .
> autoexpect as distributed does not work with the Gordon
> Chaffee Expect-for-Windows because, as you've noted, it
> relies on [interact], and that's never been available for
> Windows.  I'll speculate that autoexpect's dependence is
> fundamental, that is, that a full autoexpect coded without
> [interact] essentially replicates [interact]'s function-
> ality.  Don and Davy should know better than I, though.

Cameron is correct - you can simulate interact invocations with a few
expect commands (and vice versa).  Personally, I sometimes try writing
it both ways and then pick the one that seems easiest to read.

Quote:> If your immediate requirement is to automate FTP client
> operation from a Win* host, I have strong beliefs that
> there are more productive ways to go about it.  Are you
> using an ftp capability not available through tcllib's
> ftp package?  That's where I'd start *my* coding.

I agree with Cameron about this too.

Don

 
 
 

1. Expect: expect vs. interact

Hey Don or any other expect person:

For comparable uses, which is faster, expect or interact, or is there
any difference?

By comparable, I mean:
    expect {
        -re .+ {
            send_user -raw -- $expect_out(buffer)
            exp_continue
        }
        -i $user_spawn_id -re .+ {
            send -- $expect_out(buffer)
            exp_continue
        }
    }

vs.

    interact

or (I know, slightly different semantics)

    expect {
        "crap" { exit }
        -re .+ {
            send_user -raw -- $expect_out(buffer)
            exp_continue
        }
        -i $user_spawn_id -re .+ {
            send -- $expect_out(buffer)
            exp_continue
        }
    }

vs.

    interact {
        "crap" { exit }
    }

--

http://www.ugcs.caltech.edu/~huyle

2. how to open a port

3. Expect/Tcl Problem - "scripts expect Tcl version..."

4. S/Key for Solaris 2.x?

5. How to compile EXPECT was WANTED expect for Linux

6. Building a router on MDK 8.1

7. expect for AIX where can I find freeware.expect.rte

8. Help : Shutdown failure

9. expect-send pairs and sub expect-send pairs in chat

10. Expect: How to expect clear screen

11. Any other ways to link a linux machine to a network

12. How do i disable all ways to get access to the dos prompt on startup?

13. newbie to discussions, are there other ways to discuss?