From: John v. V. <joh...@ya...> - 2000-12-04 21:50:56
|
Hi Folks, Please help me here It appears that expect.pm is doing a lot more than I expected. I just want to receive whats coming in from the other side, pass it thru the regular regexp filters I have been using from day one, and send back the appropriate answer. I did look at the docs, and was frankly mystified. Basically this is the perl I was expecting to use: ########### $xpt_ob = new Expect ; $ssh_xpt -> spawn("/opt/ssh/bin/ssh1 -l sys_adm localhost hostname"); $first_rem_session_string = $xpt_ob -> expect ( 5, /.*/ ) ; # Or $first_rem_session_string = $xpt_ob -> the_buffer_with_string_in_it ; if ( $first_rem_session_string =~ /password/ ) { $ssh_xpt -> send $password } elsif ( $first_rem_session_string =~ /yes/no/ ) { $ssh_xpt -> send "yes\r" } else { die $first_rem_session_string } ########### The above is easily supportable. How does python do this kind of stuff ?? Also I serialized the object w/ my data::dumper wrapper and all that appeared was some bless stuff, I was hoping for the buffer string. MyFirstExpect.prl : #!/opt/perl5.5.3/bin/perl # being GBARR released 5.5.3 and 5.4 broke all my IO.pm scripts I'm sticking w/ 5.5.3 use Expect ; use CXN::PersistOB ; #this is just a wrapper for data::dumper $pob = new CXN::PersistOB ; # Optional debugging, explained later. $Expect::Debug=1 ; $Expect::Exp_Internal=1; $Expect::Log_Stdout=0; # On by default. $ssh_session=Expect->spawn("/opt/ssh/bin/ssh1 -l sys_adm localhost hostname"); $remote_ssh_string = $ssh_session->expect(10, /.*/ ); print "<STRING> $remote_ssh_string </STRING>\n" ; print $pob -> serialize( $remote_ssh_session ) ; ################################################################ OUT PUT (??) Spawned '/opt/ssh/bin/ssh1 -l sys_adm localhost hostname' spawn id(3) Pid: 5873 Tty: /dev/pts/19 Starting EXPECT pattern matching... spawn id(3): beginning expect. Timeout: 10 seconds. Current time: 975964131 spawn id(3): list of patterns: #1: -ex `1' Waiting for new data (10 seconds)... spawn id(3): new data. spawn id(3): read 30 byte(s). spawn id(3): Does `sys_adm@127.0.0.1\'s password: ' match: pattern #1: -ex `1'? YES!! Before match string: `sys_adm@' Match string: `1' After match string: `27.0.0.1\'s password: ' Matchlist: () Returning from expect successfully. spawn id(3): accumulator: `27.0.0.1\'s password: ' <STRING> 1 </STRING> $VAR1 = bless( \*Symbol::GEN0, 'Expect' ); Closing spawn id(3). Timed out waiting for an EOF from spawn id(3). spawn id(3) closed. Pid 5873 of spawn id(3) exited, Status: 65280 ===== John van Vlaanderen ############################################# # CXN, Inc. Contact: jo...@th... # # # Proud Sponsor of Perl/Unix of NY # # http://puny.vm.com # ############################################# __________________________________________________ Do You Yahoo!? Yahoo! Shopping - Thousands of Stores. Millions of Products. http://shopping.yahoo.com/ |