Z
Zebee Johnstone
I"m using Expect.pm to log into an HP ILO (management card for HP
Prliant servers) but I'm getting odd results. I'm not sure if it's
because I'm using Expect incorrectly or if the HP is in some odd way
incompatible.
The problem seems to be that the second exp->expect statement either
doesn't run or isn't sent. Or else the /n it ends with isn't sent.
Either way it doesn't seem to produce output. Should I be expecting
to see output? I certainly see the login output.
It says an EOF doesn't show up, what sort of EOF is it looking for, do
I need to tell it to look for something other than the hpiLO prompt
presumably between the 2 exp->expect statements?
Here's the code:
#!/usr/bin/perl
use warnings;
use strict;
use Expect;
my $username = "username";
my $box = "ILOcard";
my $password = "password";
my $timeout=100;
my $exp = new Expect;
$exp->raw_pty(1);
$exp->debug(2);
$exp->log_file("hplog");
$exp->spawn("ssh $box -l $username") or die "Cannot spawn ssh : $!\n";
my $spawn_ok;
$exp->expect($timeout, ['assword:', sub {my $self = shift; $self->send("$password\n");}]);
$exp->expect($timeout, ['hpiLO->', sub {my $self = shift; $self->send("show /map1\n");}]);
$exp->send("\n");
# Destroy the expect object
$exp->soft_close();
Here's what an interactive session looks like:
<localbox>$ ssh ILOcard -l username
username@ILOcard's password:
User:username logged-in to ILOcard.(10.0.1.1)
iLO 2 Advanced 1.80 at 10:12:14 Oct 30 2009
Server Name: ILOcard
Server Power: On
</>hpiLO-> show /map1
status=0
status_tag=COMMAND COMPLETED
/map1
Targets
firmware1
accounts1
[...] #no need to show all output
</>hpiLO-> exit
And here's what the session from the script looks like. Note that the
debug shows the end session called before the show /map1 is given, and
the map1 output never shows up.
Spawned 'ssh ILOcard -l username'
spawn id(3)
Pid: 29291
Tty: /dev/pts/64
Expect::spawn('Expect=GLOB(0x278f1c)', 'ssh ILOcard
-l username') called at o
ldhpmgmt.pl line 22
Starting EXPECT pattern matching...
Expect::expect('Expect=GLOB(0x278f1c)', 100,
'ARRAY(0x29039c)') called at oldhpmgmt.pl line 2
9
username@ILOcard's password: Starting EXPECT pattern
matching...
Expect::expect('Expect=GLOB(0x278f1c)', 100,
'ARRAY(0x224f54)') called at oldhpmgmt.pl line 3
0
User:username logged-in to ILOcard.(10.120.220.122)
iLO 2 Advanced 1.80 at 10:12:14 Oct 30 2009
Server Name: ILOcard
Server Power: On
</>hpiLO-> Closing spawn id(3).
Expect::soft_close('Expect=GLOB(0x278f1c)') called at
oldhpmgmt.pl line 35
show /map1Timed out waiting for an EOF from spawn id(3).
spawn id(3) closed.
Pid 29291 of spawn id(3) exited, Status: 0x01
Closing spawn id(3).
Expect::hard_close('Expect=GLOB(0x278f1c)') called at
/usr/perl5/site_perl/5.8.4/Expect.pm li
ne 1621
Expect:ESTROY('Expect=GLOB(0x278f1c)') called at
oldhpmgmt.pl line 0
eval {...} called at oldhpmgmt.pl line 0
<localbox>$
Prliant servers) but I'm getting odd results. I'm not sure if it's
because I'm using Expect incorrectly or if the HP is in some odd way
incompatible.
The problem seems to be that the second exp->expect statement either
doesn't run or isn't sent. Or else the /n it ends with isn't sent.
Either way it doesn't seem to produce output. Should I be expecting
to see output? I certainly see the login output.
It says an EOF doesn't show up, what sort of EOF is it looking for, do
I need to tell it to look for something other than the hpiLO prompt
presumably between the 2 exp->expect statements?
Here's the code:
#!/usr/bin/perl
use warnings;
use strict;
use Expect;
my $username = "username";
my $box = "ILOcard";
my $password = "password";
my $timeout=100;
my $exp = new Expect;
$exp->raw_pty(1);
$exp->debug(2);
$exp->log_file("hplog");
$exp->spawn("ssh $box -l $username") or die "Cannot spawn ssh : $!\n";
my $spawn_ok;
$exp->expect($timeout, ['assword:', sub {my $self = shift; $self->send("$password\n");}]);
$exp->expect($timeout, ['hpiLO->', sub {my $self = shift; $self->send("show /map1\n");}]);
$exp->send("\n");
# Destroy the expect object
$exp->soft_close();
Here's what an interactive session looks like:
<localbox>$ ssh ILOcard -l username
username@ILOcard's password:
User:username logged-in to ILOcard.(10.0.1.1)
iLO 2 Advanced 1.80 at 10:12:14 Oct 30 2009
Server Name: ILOcard
Server Power: On
</>hpiLO-> show /map1
status=0
status_tag=COMMAND COMPLETED
/map1
Targets
firmware1
accounts1
[...] #no need to show all output
</>hpiLO-> exit
And here's what the session from the script looks like. Note that the
debug shows the end session called before the show /map1 is given, and
the map1 output never shows up.
Spawned 'ssh ILOcard -l username'
spawn id(3)
Pid: 29291
Tty: /dev/pts/64
Expect::spawn('Expect=GLOB(0x278f1c)', 'ssh ILOcard
-l username') called at o
ldhpmgmt.pl line 22
Starting EXPECT pattern matching...
Expect::expect('Expect=GLOB(0x278f1c)', 100,
'ARRAY(0x29039c)') called at oldhpmgmt.pl line 2
9
username@ILOcard's password: Starting EXPECT pattern
matching...
Expect::expect('Expect=GLOB(0x278f1c)', 100,
'ARRAY(0x224f54)') called at oldhpmgmt.pl line 3
0
User:username logged-in to ILOcard.(10.120.220.122)
iLO 2 Advanced 1.80 at 10:12:14 Oct 30 2009
Server Name: ILOcard
Server Power: On
</>hpiLO-> Closing spawn id(3).
Expect::soft_close('Expect=GLOB(0x278f1c)') called at
oldhpmgmt.pl line 35
show /map1Timed out waiting for an EOF from spawn id(3).
spawn id(3) closed.
Pid 29291 of spawn id(3) exited, Status: 0x01
Closing spawn id(3).
Expect::hard_close('Expect=GLOB(0x278f1c)') called at
/usr/perl5/site_perl/5.8.4/Expect.pm li
ne 1621
Expect:ESTROY('Expect=GLOB(0x278f1c)') called at
oldhpmgmt.pl line 0
eval {...} called at oldhpmgmt.pl line 0
<localbox>$