From: Zebee Johnstone on
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(a)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(a)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::DESTROY('Expect=GLOB(0x278f1c)') called at
oldhpmgmt.pl line 0
eval {...} called at oldhpmgmt.pl line 0
<localbox>$

From: Josef Moellers on
Am 30.6.2010 schrub 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.

At times, Expect can be very confusing and tiresome.

> 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.

You don't send linefeeds ("\n"), you send carriage-returns ("\r")!

The machine will, most likely, respond with a carriage-return/linefeed
combination ("\r\n"), that you should be aware of, although the exact
order may very well not be specified, so I usually expect that as "[\r\n]+".

> Either way it doesn't seem to produce output. Should I be expecting
> to see output? I certainly see the login output.

There is one very useful method:

$exp->exp_internal(0 | 1);

It will tell you what exactly Expect receives and what it is looking for.

Josef
--
These are my personal views and not those of Fujitsu Technology Solutions!
Josef M´┐Żllers (Pinguinpfleger bei FTS)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html
From: Zebee Johnstone on
In comp.lang.perl.misc on Wed, 30 Jun 2010 09:04:13 +0200
Josef Moellers <josef.moellers(a)ts.fujitsu.com> wrote:
> Am 30.6.2010 schrub 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.
>
> At times, Expect can be very confusing and tiresome.

So I'm discovering!

>
>> 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.
>
> You don't send linefeeds ("\n"), you send carriage-returns ("\r")!

hurrah! yes that's it, thank you. (although linefeed works for the
password, I suppose the ssh authentication is handled by a different
beastie)

Which also explains some things in the Net::SSH::Expect perldoc that
was confusing me.

zebee