Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Expect: line endings?

Reply
Thread Tools

Expect: line endings?

 
 
Zebee Johnstone
Guest
Posts: n/a
 
      06-30-2010
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>$

 
Reply With Quote
 
 
 
 
Josef Moellers
Guest
Posts: n/a
 
      06-30-2010
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
 
Reply With Quote
 
 
 
 
Zebee Johnstone
Guest
Posts: n/a
 
      06-30-2010
In comp.lang.perl.misc on Wed, 30 Jun 2010 09:04:13 +0200
Josef Moellers <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Read a file line by line and write each line to a file based on the5th byte scad C++ 23 05-17-2009 06:11 PM
How to read a text file line by line and remove some line kaushikshome C++ 4 09-10-2006 10:12 PM
Beginner: read $array with line breaks line by line Marek Stepanek Perl Misc 12 09-02-2006 10:27 AM
Read a file line by line with a maximum number of characters per line Hugo Java 10 10-18-2004 11:42 AM
Use of uninitialized value in concatenation (.) at register.pl line 38, <STDIN> line 10. G Kannan Perl 1 10-11-2003 11:58 AM



Advertisments