Sent from my iPad

On Jul 9, 2012, at 3:42 PM, Atahualpa Ledesma <atahualpa.ledesma@gmail.com> wrote:

I'm trying to automate something using Perl and Expect.pm using a virtual serial port on an HP server using ILO3, but somehow when i try to start a virtual console from Expect created pty, it just freezes there, and doesn't start, but if i do it manually via ssh then it works, i think it is an stty/pty issue but i don't know where to start debugging this.

This is a simpler version of what i am doing:

#!/usr/bin/perl
use strict;
use warnings;
use Expect;

my $iloip = "1.2.3.4"; # IP changed to protect the guilty
my $ilouser = "Administrator";
my $ilopswd = "mypass"; #same
my $osuser = "admin";
my $ospassword = "SecurePassword!"; #same

my $expect = Expect->new();
   $expect->log_stdout(1); #debug
   $expect->exp_internal(1); #debug
   $expect->spawn("ssh $ilouser\@$iloip");
   $expect->expect(10, "ssword:");
   $expect->send("$ilopswd\n");
   $expect->expect(10, "iLO->");
   $expect->send("vsp\n");
   $expect->expect(20, "login:");
 .....

After issuing the vsp command, i should get a login prompt ( on the server there is a console configuration on /etc/inittab using agetty [co:2345:respawn:/sbin/agetty ttyS0 115200 vt102] ) but nothing happens.

If i do the same commands on a manually initiated ssh session then it works correctly

Example:

Script output:

[dev@dev-ipdr-01 standalone]$ perl rconsole.pl 
Spawned 'ssh Administrator@1.2.3.4'
spawn id(3)
Pid: 27108
Tty: /dev/pts/0
 at /usr/share/perl5/vendor_perl/Expect.pm line 181
Expect::spawn('Expect=GLOB(0x19ad360)', 'ssh Administrator@1.2.3.4') called at rconsole.pl line 15
Starting EXPECT pattern matching...
 at /usr/share/perl5/vendor_perl/Expect.pm line 561
Expect::expect('Expect=GLOB(0x19ad360)', 10, 'ssword:') called at rconsole.pl line 16
spawn id(3): list of patterns:
  #1: -ex `ssword:'

spawn id(3): Does `'
match:
  pattern #1: -ex `ssword:'? No.

Administrator@1.2.3.4's password: 
spawn id(3): Does `Administrator@1.2.3.4\'s password: '
match:
  pattern #1: -ex `ssword:'? YES!!
    Before match string: `Administrator@1.2.3.4\'s pa'
    Match string: `ssword:'
    After match string: ` '
    Matchlist: ()
Sending 'mypass\n' to spawn id(3)
 at /usr/share/perl5/vendor_perl/Expect.pm line 1264
Expect::print('Expect=GLOB(0x19ad360)', 'mypass!\x{a}') called at rconsole.pl line 17
Starting EXPECT pattern matching...
 at /usr/share/perl5/vendor_perl/Expect.pm line 561
Expect::expect('Expect=GLOB(0x19ad360)', 10, 'iLO->') called at rconsole.pl line 18
spawn id(3): list of patterns:
  #1: -ex `iLO->'

spawn id(3): Does ` '
match:
  pattern #1: -ex `iLO->'? No.

spawn id(3): Does ` \r\n'
match:
  pattern #1: -ex `iLO->'? No.

User:Administrator logged-in to 
spawn id(3): Does ` \r\nUser:Administrator logged-in to '
match:
  pattern #1: -ex `iLO->'? No.

ilo1.solutions.net(1.2.3.4)
iLO 3 Advanced 1.28 at  Jan 13 2012
Server Name: FOOBAR
Server Power: On

</>hpiLO-> 
spawn id(3): Does ` \r\nUser:Administrator logged-in to ilo1.solutions.net(1.2.3.4)\r\niLO 3 Advanced 1.28 at  Jan 13 2012\r\nServer Name: FOOBAR\r\nServer Power: On\r\n\n</>hpiLO-> '
match:
  pattern #1: -ex `iLO->'? YES!!
    Before match string: ` \r\nUser:Administrator logged-in to ilo1.solutions.net(1.2.3.4)\r\niLO 3 Advanced 1.28 at  Jan 13 2012\r\nServer Name: FOOBAR\r\nServer Power: On\r\n\n</>hp'
    Match string: `iLO->'
    After match string: ` '
    Matchlist: ()
Sending 'vsp\n' to spawn id(3)
 at /usr/share/perl5/vendor_perl/Expect.pm line 1264
Expect::print('Expect=GLOB(0x19ad360)', 'vsp\x{a}') called at rconsole.pl line 19
Starting EXPECT pattern matching...
 at /usr/share/perl5/vendor_perl/Expect.pm line 561
Expect::expect('Expect=GLOB(0x19ad360)', 20, 'login:') called at rconsole.pl line 20
spawn id(3): list of patterns:
  #1: -ex `login:'


spawn id(3): Does ` '
match:
  pattern #1: -ex `login:'? No.

vsp

spawn id(3): Does ` vsp\n'
match:
  pattern #1: -ex `login:'? No.

[dev@dev-ipdr-01 standalone]$ 


Now this is the output of a manual ssh connection:

dev@dev-ipdr-01 standalone]$ ssh Administrator@1.2.3.4
Administrator@10.2.3.4's password: 
User:Administrator logged-in to ilo1.solutions.net(1.2.3.4)
iLO 3 Advanced 1.28 at  Jan 13 2012
Server Name: FOOBAR
Server Power: On

</>hpiLO-> vsp 

Virtual Serial Port Active: COM1

Starting virtual serial port.
Press 'ESC (' to return to the CLI Session.



foobar.foo.myboxen.lan login:
 

-END-

I tried to see the stty options on the ssh connection's pty and the Expect spawn'ed pty:

SSH PTY:

[dev@dev-ipdr-01 ~]$ stty -F /dev/pts/2
speed 38400 baud; line = 0;
eol = M-^?; eol2 = M-^?; lnext = <undef>; min = 1; time = 0;
-icrnl
-icanon -echo

EXPECT IO::Pty PTY:

[dev@dev-ipdr-01 ~]$ stty -F /dev/pts/0
speed 38400 baud; line = 0;
min = 1; time = 0;
-brkint -icrnl -imaxbel
-opost
-isig -icanon -iexten -echo -echoe -echok



How can i debug this? Is there anyway to see if there is something in the pty settings that ILO is setting up?



--
--------------------------------------------------
Atahualpa Ledesma
Redhat Certified Engineer
Oracle Certified Professional 9i
Unix/Linux/Oracle Consultant
atahualpa.ledesma@gmail.com

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Expectperl-discuss mailing list
Expectperl-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/expectperl-discuss