problem connecting pipes in Expect.pm

From: Mike (mikee_at_mikee.ath.cx)
Date: 11/26/03

  • Next message: Anthony DiPierro: "avoiding WWW::Mechanize, LWP::Useragent man-in-the-middle attack"
    Date: Wed, 26 Nov 2003 19:25:34 -0000
    
    

    Here is a script I'm working on to connect to various lpars
    that are connected to my local HMC. The script creates the
    proper magic string and is then connected to the intended
    lpar, but then the script does not connect the user's stdin
    with the telnet session. What am I doing wrong in this
    script?

    Mike

    #!/usr/bin/perl

    # $Id$
    # $Log$

    use Expect;
    use strict;

    sub usage {
            exit 0;
    }

    usage if $ARGV[0] eq '-h';

    my %hostdefs = (
            'drtest' => { 'machtype' => '7028-6C4', 'serno' => '10BCCDA', 'lpar' => 2 },
            'txwasp01' => { 'machtype' => '7038-6M2', 'serno' => '1021A4A', 'lpar' => 2 },
            'txwasp02' => { 'machtype' => '7038-6M2', 'serno' => '103053A', 'lpar' => 1 },
            'txwasq01' => { 'machtype' => '7038-6M2', 'serno' => '103053A', 'lpar' => 2 },
            'txwast01' => { 'machtype' => '7038-6M2', 'serno' => '1021A4A', 'lpar' => 1 },
            'txmqsp01' => { 'machtype' => '7028-6C4', 'serno' => '10BCCDA', 'lpar' => 1 },
            'txmqsp02' => { 'machtype' => '7028-6C4', 'serno' => '10DD09A', 'lpar' => 1 },
            'txmqsq01' => { 'machtype' => '7028-6C4', 'serno' => '10DD09A', 'lpar' => 3 },
            'txmqst01' => { 'machtype' => '7028-6C4', 'serno' => '10DD09A', 'lpar' => 2 }
    );

    sub findlpar {
            my $host = shift;
            die "$0: lpar not found for host '$host'"
                            if $hostdefs{$host}->{'lpar'} == undef;
            return $hostdefs{$host}->{'lpar'} or die "$0: lpar not found for host '$host'";
    }

    sub findmachtype {
            my $host = shift;
            die "$0: machine type not found for host '$host'"
                            if $hostdefs{$host}->{'machtype'} == undef;
            return $hostdefs{$host}->{'machtype'};
    }

    sub findserno {
            my $host = shift;
            die "$0: serial number not found for host '$host'"
                            if $hostdefs{$host}->{'serno'} == undef;
            return $hostdefs{$host}->{'serno'};
    }

    my $cmd = 'telnet'; # connection command
    my $start = 'FFFX';
    my $hmchost = 'txhmc001'; # hmc host
    my $host = shift; # lpar to connect to
    my $hmcport = 9735; # port on the hmc
    my $lparport = 9734; # default telnet connection port for the lpars
    my $lparno = findlpar($host);
    my $machtype = findmachtype($host);
    my $serno = findserno($host);
    my $sesno = 1;

    my $constrpart = join('*', $hmchost, $lparport, $lparno, $machtype,
                            $serno, $sesno);
    my $constr = $start . length($constrpart) . '*' . $constrpart;

    print $constr, "\n";
    my $stdin = Expect->exp_init(\*STDIN);
    $stdin->manual_stty(1);

    my $exp = new Expect;
    $exp->slave->clone_winsize_from(\*STDIN);
    $exp = Expect->spawn("$cmd $hmchost $hmcport")
                    or die "Cannot spawn $cmd: $!\n";

    # prepare for window resizing
    $SIG{WINCH} = \&winch;

    sub winch {
            $exp->slave->clone_winsize_from(\*STDIN);
            kill WINCH => $exp->pid if $exp->pid;
            $SIG{WINCH} = \&winch;
    }

    # wait for connection prompt
    unless($exp->expect(30, 'scape')) {
            die "timeout waiting for connection string";
    }
    $exp->send($constr . "\n");

    # wait for lpar connection
    unless($exp->expect(30, 'ogin:')) {
            die "timeout waiting for lpar connection";
    }

    # make sure telnet is in character mode
    $exp->send("\n");
    unless($exp->expect(30, "mode character\n")) {
            die "timeout waiting for mode set conformation";
    }
    $exp->send("\n");

    # turn control back to the user
    $stdin->set_group($exp);
    $exp->set_group($stdin);
    Expect::interconnect($stdin, $exp);


  • Next message: Anthony DiPierro: "avoiding WWW::Mechanize, LWP::Useragent man-in-the-middle attack"

    Relevant Pages

    • problem connecting pipes in Expect.pm
      ... Here is a script I'm working on to connect to various lpars ... lpar, but then the script does not connect the user's stdin ... sub findlpar { ... # wait for connection prompt ...
      (comp.lang.perl.misc)
    • magic string to HMC
      ... Here is a script I'm working on to connect to various lpars ... lpar, but then the script does not connect the user's stdin ... sub findlpar { ... # wait for connection prompt ...
      (comp.unix.aix)
    • Scripting: Zipping files and checking Network Share
      ... I am trying to write a script that performs a few specific ... Copy source files to destination only if they do not exsist on the ... out how to have it loop until a successful connection is made - and send out ... Sub CopySource() ...
      (microsoft.public.scripting.vbscript)
    • Re: Scripting: Zipping files and checking Network Share
      ... I am trying to write a script that performs a few specific ... Copy source files to destination only if they do not exsist on the ... out how to have it loop until a successful connection is made - and send ... Sub CopySource() ...
      (microsoft.public.scripting.vbscript)
    • Re: Macro Message box doesnt display output?
      ... Thanks alot Jim, that's worked a treat. ... > Sub Button5_Click ... > 'WScript.echo "No connection available" ... > I have a script which is linked as a macro to a button on a worksheet. ...
      (microsoft.public.excel.programming)