Expect part2

Robert L. Harris Robert.L.Harris at rdlg.net
Tue May 21 11:05:17 CDT 2002



Many thanks for everyone who told me to search for expect.  One day
that'll stick in my long term memory and I'll look before I open my
mouth.

Is anyone actually using this?  I've got a working piece of code that's
behaving a bit wierd.  Basically I'm trying to go through a list of
servers, ssh to each and run a command, then sort the output.  The loop
works fine of course but something in my expect logic is flawed:

  $exp->expect($timeout,
    [
      'password: ',
      sub {
        $spawn_ok = 1;
        $fh=shift;
        print $fh "$passwd\n";
        exp_continue;
      }
    ],
    [
      'you sure you want to continue connecting',
      sub {
        $fh=shift;
        $fh->send("yes\n");
        exp_continue;
      }
    ],
    [
       timeout =>
       sub {
         die "No login.\n";
       }
    ],
      '-re', qr'[#>:] $', #' wait for shell prompt, then exit expect
   );


When I connect to a host that doesn't have the key set up I want to put
it in the known_hosts and continue.  It's a relatively small, very
secure environment so this isn't a security concern at this pint.  At
anyrate though I see the output to my screen and it just sits waiting
for "yes" to be sent.

Any ideas off the top of your heads?  At lunch I'm going for an expect
book.  The expect sourceforge page isn't very helpful at the moment.



:wq!
---------------------------------------------------------------------------
Robert L. Harris                |  Micros~1 :
Senior System Engineer          |    For when quality, reliability
  at RnD Consulting             |      and security just aren't
                                \_       that important!
DISCLAIMER:
      These are MY OPINIONS ALONE.  I speak for no-one else.
FYI:
 perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'




More information about the Pikes-peak-pm mailing list