Issue with Expect 1.21

Hello Folks! Env=SUSE 10.2 Linux, Perl 5.14.2, Expect v1.21
I really need some help - this issue has tied me up 4 days now....
I am trying to use Expect to ssh from a SuSE server to a Solaris 8 server.
The manual dialog for this login is:
>ssh -o StrictHostkeyChecking=no user@sol8server
Could not create directory '/appl/user/.ssh'.
Failed to add the host to the list of known hosts (/appl/user/.ssh/known_hosts).
user@sol8server's password: 
Last login: Tue Mar 20 13:43:00 2012 from xxx
Could not chdir to home directory /home/user: No such file or directory
MANAGEMENT APPROVED PURPOSES ONLY
**** SYSTEM ACTIVITIES MAY BE MONITORED ****
sol8server% ls
blah blah blah           etc                  lost+found           op                   sbin                 vol
sol8server% logout
Connection to sol8server closed.
>

Open in new window

My expect code spawns the ssh command all ok and it complete the login and password ok.
Then I try to send the 'ls' command and I never get anything back in response - it is like the send command never happens.
This is driving me crazy. I copied the code from pl scripts I wrote a few years ago
on Sol8 and they all worked perfectly - I just don't understand what the issue is.
Back then I was using Perl 5.8.8 on Solaris8 and Expect 1.15. - never ever had any issues.
My Code:

my $expTimeOut = 6;		# 6 secs 
my $expPty = 1;			# pty mode
my $expDebug = 3;		# Expect debug level
# Build Expect object
######################################################
$sshFW = Expect->new;		# create Expect object
$sshFW->debug($expDebug);		# debugging
$sshFW->log_file($expFWLogFile, "w");		# open Expect log with overwrite mode
$sshFW->raw_pty($expPty);
######################################################
# Spaw a ssh session
######################################################
$cmd = "ssh -o StrictHostkeyChecking=no $usr\@$FWHost";
print "\nSpawing command [$cmd]\n\n";#debug	
if (!$sshFW->spawn($cmd)) {
	# spawn failed
	$msg = "Error,Spawn cmd [$cmd] failed for device [$FWHost].\n";
	print $msg;
	$sshFW->hard_close;		# release object
	die $msg;		#abort program!
}		# endif
$msg = "\nSuccessful spawn cmd [$cmd]\n\n";
print $msg;
######################################################
# OK, we got a good spawn! now try login sequence
######################################################
$expFWStatus = 0;
$expFWmatchString = "";
@exp_stat = $sshFW->expect($expTimeOut,
	[qr /password: $/ =>				# got password prompt
	sub {
		my $self = shift;
		$self->send("$passw\r");
		print "Sent password!\n";#debug
        exp_continue; 		# responded to password prompt, continue
    	}		# end sub
	],
	# Timeout trap
	[timeout =>
	sub {
		$expFWStatus = 1;
		$expFWmatchString = $sshFW->match;
		print "Error,Timeout while waiting $expTimeOut secs for login on [$FWHost] user[$usr]. Error:" . $sshFW->exp_error() . "\n";	
	}
	],
	# EOF trap
	[eof =>
	sub {
		$expFWStatus = 2;
		$expFWmatchString = $sshFW->match;
		print "Error,Premature EOF during login for [$FWHost] user[$usr]. Error:" . $sshFW->exp_error() . "\n";
	}
	],

	'-re', qr /% $/, 			# wait for device prompt '%' and exit expect; all logged in now
	);		# End expect for Login processing

print "\nFinished processing FW login expect expFWstatus[$expFWStatus]\n\n";		# debug	
if ($expFWStatus) {			# check results of login attempt 
	$msg = "Login failed, returning. expFWStatus[$expFWStatus]. Last string matched was [$expFWmatchString]\n";		# debug
	print $msg;
	die $msg;		# abort ptogram
}		# endif
$msg = "\nInfo,Login OK for [$FWHost] user[$usr]\n\n";
print $msg;
print Dumper(\@exp_stat);#debug

#############################################
print "\nSending ls command!\n\n";
$sshFW->send("ls\r");

@exp_stat = $sshFW->expect($expTimeOut,

	# Timeout trap
	[timeout =>
	sub {
		$expFWStatus = 1;
		$expFWmatchString = $sshFW->match;
		print "Error,Timeout while waiting $expTimeOut secs for ls command on [$FWHost] user[$usr]. Error:" . $sshFW->exp_error() . "\n";	
	}
	],
	# EOF trap
	[eof =>
	sub {
		$expFWStatus = 2;
		$expFWmatchString = $sshFW->match;
		print "Error,Premature EOF during ls command for [$FWHost] user[$usr]. Error:" . $sshFW->exp_error() . "\n";
	}
	],

	'-re', qr /% $/, 			# wait for device prompt '%' and exit expect; all logged in now
	);		# End expect 

print "\nContinuing\n\n";
print Dumper(\@exp_stat);#debug

print "\nClosing connection to FW Host [$FWHost].\n\n";
$sshFW->send("logout\r");
	if (!$sshFW->expect($expTimeOut, 'closed.')) {
	print "Warning,Did not get connection closed on [$FWHost]. Error:" . $sshFW->exp_error() . "\n";
	print "Warn: Issue with closing FW Host [$FWHost].\n";
	}		# endif
	else {
		# ok, we got the logout comfirmation....
		print "Info,Connection closed: [$FWHost].\n";
	}

$sshFW->soft_close;
print "\nConnection closed to FW Host [$FWHost].\n\n";
exit;

Open in new window


######################################################

Screen shots of expect debugs:
Spawing command [ssh -o StrictHostkeyChecking=no user@sol8server]

Spawned 'ssh -o StrictHostkeyChecking=no user@sol8server'
        spawn id(3)
        Pid: 29798
        Tty: /dev/pts/1
 at /export/core/perl5/5.14.2/lib/site_perl/5.14.2/Expect.pm line 181
        Expect::spawn('Expect=GLOB(0x65ca28)', 'ssh -o StrictHostkeyChecking=no user@sol8server') called at ./fwlogin.pl line 35

Successful spawn cmd [ssh -o StrictHostkeyChecking=no user@sol8server]

Starting EXPECT pattern matching...
 at /export/core/perl5/5.14.2/lib/site_perl/5.14.2/Expect.pm line 561
        Expect::expect('Expect=GLOB(0x65ca28)', 6, 'ARRAY(0x9ad490)', 'ARRAY(0x9ad9e8)', 'ARRAY(0x9bbb88)', '-re', 'Regexp=REGEXP(0x9bc050)') called at ./fwlogin.pl line 73
Could not create directory '/appl/user/.ssh'.
Failed to add the host to the list of known hosts (/appl/user/.ssh/known_hosts).
user@sol8server's password: Sent password!

Last login: Thu Mar 22 15:00:26 2012 from xxx
Could not chdir to home directory /home/user: No such file or directory
MANAGEMENT APPROVED PURPOSES ONLY
**** SYSTEM ACTIVITIES MAY BE MONITORED ****
sol8server% 
Finished processing FW login expect expFWstatus[0]


Info,Login OK for [sol8server] user[user]

$VAR1 = [
          4,
          undef,
          '% ',
          '
Last login: Thu Mar 22 15:00:26 2012 from xxx
Could not chdir to home directory /home/user: No such file or directory
MANAGEMENT APPROVED PURPOSES ONLY
**** SYSTEM ACTIVITIES MAY BE MONITORED ****
sol8server',
          '',
          bless( \*Symbol::GEN0, 'Expect' )
        ];

Sending ls command!

Starting EXPECT pattern matching...
 at /export/core/perl5/5.14.2/lib/site_perl/5.14.2/Expect.pm line 561
        Expect::expect('Expect=GLOB(0x65ca28)', 6, 'ARRAY(0x9ad6a0)', 'ARRAY(0x9bc308)', '-re', 'Regexp=REGEXP(0x9ad418)') called at ./fwlogin.pl line 109
Error,Timeout while waiting 6 secs for ls command on [sol8server] user[user]. Error:1:TIMEOUT

Continuing

$VAR1 = [
          undef,
          '1:TIMEOUT',
          undef,
          '',
          undef,
          undef
        ];

Open in new window

As you can see directly above, for some reason my expect info is nulled out????
I would apprecite any help or suggestions - I'm getting desperate now. :(
STYX757Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

STYX757Author Commented:
Resolved! Apparently Solaris 8 likes to have it's responses and commands terminated with \n and not \r.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.