From: Hailey N. <Hai...@Su...> - 2003-10-03 20:56:33
|
Hi D. Basham, It's definitely very helpful. Chris Muth has sent me an example and I got my stuff to work with that. But your info is also a great help to me. Thanks, HAiley > > >>>> Note: A know B but doesn't know C - in another words, to get to C you > have >>>> to go through B. > > Yes.. well, I guess it depends on what you're trying to say behind the > words. Remember that you're spawning ONE process (or should be). Once > you've done that and successfully logged into A, you should INVOKE telnet > client on A to get to B, so there's no more "spawning" (from a perl module > perspective), as B and C have no clue what the heck SPAWN is.. they just > know what telnet is. Just imagine that you are invoking telnet on the > command line from host to host to host, and that's ultimately what expects > doing with the single telnet session you spawned to A. Imagine it that > way and you should be able to see enough of what's going on to know how > to use expect and code it. Remember that each time you hop, the STDOUT > and STDERR channels get lashed together, and become STDIN to the thing > that created it (parent.) They all get lashed together like the Alaskan > pipeline, all the way back to your original spawned process in your > expect script. In this daisy-chain telnet example you're trying to do, > it is the only STDIN that your script should be dealing with. > > I don't know if that's the understanding you need, or if I'm confusing you > more. Bottom line, If you can do it from the command line, i.e., telnet > from A to B to C and so forth, then so can expect. If you can't do it, > then neither can expect. It's that simple. All expect does is provide a > way to automate the steps. The only difference between opening a process > in Perl vs. Expect is that perl (by itself) cannot open a bi-directional > pipe to a process. I.e., it can do this > > open (TELNET, " telnet $HOSTA | "); > > which would allow you to read from the session, or you can do this: > > open (TELNET, "| telnet $HOSTA "); > > to write to the process, but you cannot do both at the same time like > this: > > open (TELNET, "| telnet $HOSTB | "); > > that's where Expect can help. The telnet module is an alternative that > also does this, but only for telnet. Can't spawn a chess program on the > command line and interact with it using telnet module, but you can do it > using Expect (for all you telnet.pm zealots out there, that's the > difference) > > If you want to look at primitive code that represents this idea, then it > would look something like this: > > use Expect; > > $HOSTA=xx.xx.xx.1; > $HOSTB=xx.xx.xx.2; > $HOSTC=xx.xx.xx.3; > > $username="abc"; > $password="123"; > ># ------------ ># telnet to A ># ------------ > my $exp = Expect->spawn("telnet $HOSTA") or die "Cannot spawn telnet: $! > \n"; > $timeout=20; > expect($timeout, "login: "); > $exp->send("$username\n"); > expect($timeout, "password: "); > $exp->send("$password\n"); > $expect($timeout, '-re', "[%#>] $"); # $HOSTA prompt > ># ------------ ># telnet to B ># ------------ > $exp->send("telnet $HOSTB\n"); > expect($timeout, "login: "); > $exp->send("$username\n"); > expect($timeout, "password: "); > $exp->send("$password\n"); > $expect($timeout, '-re', "[%#>] $"); # $HOSTB prompt > ># ------------ ># telnet to C ># ------------ > $exp->send("telnet $HOSTC\n"); > expect($timeout, "login: "); > $exp->send("$username\n"); > expect($timeout, "password: "); > $exp->send("$password\n"); > $expect($timeout, '-re', "[%#>] $"); # $HOSTC prompt > > > Braindead simple example, but you should get the idea. Do a perldoc on > Expect.pm and print it out, go to staples and buy a binder, put it in > there and carry it around / put it on your desk at work also. If you > REALLY want to get nuts and rule the world with Expect, go out and buy > Don Libes most excellent O'Reilly book. Tcl is such a simple language, > that you would have no problem figuring enough of it out on the fly to > literally use this book as a supercharged reference for the Perl module, > that is, unless you're a Perl zealot and can't for religious reasons.. > although the perl module is not 100% translation, it's close enough for > government work (so the saying goes.) > > > Anyways, hope this helps you man. > > > > > > > Hailey Nguyen > <Hai...@Su...> To: > Chris Muth <mut...@mc...> Sent > by: cc: Hailey Nguyen > <Hai...@Su...>, > exp...@li...urc > exp...@li... > eforge.net Subject: Re: > [Expectperl-discuss] Nested telnet > sessions using Expect.pm module > 10/02/2003 04:11 PM > > > > > > > > Hi Chris, > >>>> First you will have to login to A. That involves what you have, plus >>>> you will have to $exp->expect() for whatever telnet responds with when >>>> it asks for the password. Then use a $exp->send() to send the > password. >>>> Then $exp->expect() for the prompt on A. Once you are logged into A, >>>> use a $exp->send() to call telnet $B on A to login to B, $exp->expect() >>>> for the password prompt, and then $exp->send() it. Once logged into B, >>>> do the same to login to C, and the same for D, and the same for ... > > Still struggling with this. As soon as I logged into B from A I lose > control of that session/connection. So $exp->send() won't do anything. > Did you write something like this before. Can I have an example? > > Note: A know B but doesn't know C - in another words, to get to C you > have to go through B. > > Thanks a million, > Hailey > > >>>>> >>>>> Please show me how to do nested telnet sessions using Expect.pm > module? >>>>> >>>>> 1- telnet to machine A >>>>> 2- from A to mcahine B >>>>> 3- from B to machine C >>>>> >>>>> ----- >>>>> use Expect; >>>>> >>>>> my $exp = Expect->spawn("telnet $somehost") >>>>> or die "Cannot spawn telnet: $!\n"; >>>>> >>>>> ... >>>>> >>>>> ----- >>>>> Your help is greatly appreciated. Please reply directly to me since >>>>> I am not on the alias. >>>>> > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > > |