problem connecting pipes in Expect.pm
From: Mike (mikee_at_mikee.ath.cx)
Date: 11/26/03
- Next message: Edo: "keeping anonymous hash sorted"
- Previous message: Eric Lewton: "Re: script works from prompt but not through telnet"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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: Edo: "keeping anonymous hash sorted"
- Previous message: Eric Lewton: "Re: script works from prompt but not through telnet"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|