Thanks!!!! I will check the info out.
Hey is there a better way to code my "giant" Expect clause, I'd sure appreciate any suggestions. I was just following the example I was given by a person who introduced to me Expect.pm.
Thanks - I appreciate the advise! | [reply] [Watch: Dir/Any] |
So I reviewed the other thread and looked at FAQ. I am using Data Dumper now, still no luck.
I wrote a smaller program to ssh to another unix server and I get the same issue, right after i send the user password for login (that works ok, I get my login completed), I cannot send or expect anything else after that procedure completes. Right after the login procedure completes, i try to send a ls command and expect - all i get is timeout:
screen shot:
Sending ls command!
Starting EXPECT pattern matching...
at /export/dmzsupp/perl5/5.14.2/lib/site_perl/5.14.2/Expect.pm line 5
+61
Expect::expect('Expect=GLOB(0x65ca28)', 6, 'ARRAY(0x9b6460)',
+'ARRAY(0x9b6328)', '-re', 'Regexp=REGEXP(0x9990d8)') called at ./fwlo
+gin.pl line 42
Error,Timeout while waiting 6 secs for ls command on [sol8server] user
+[user]. Error:1:TIMEOUT
Continuing
$VAR1 = [
undef,
'1:TIMEOUT',
undef,
'',
undef,
undef
];
The code:
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 com
+mand 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] use
+r[$usr]. Error:" . $sshFW->exp_error() . "\n";
}
],
'-re', qr /% $/,
); # End expect, got Unix prompt ok
print "\nContinuing\n\n";
print Dumper(\@exp_stat);#debug
# The above behaves just like the ls command was never sent!
| [reply] [Watch: Dir/Any] [d/l] |
Why are you terminating sends with "\r" and not "\n"?
#!/usr/bin/env perl
use 5.014;
use warnings;
use Expect;
my $exp = Expect->new;
$exp->spawn('ssh tak');
$exp->expect(10, '~$ '); # prompt. using ssh keys so no password
$exp->send("ls\n");
$exp->expect(10, '~$ ');
$exp->send("exit\n");
$exp->soft_close();
__END__
Output:
zengargoyle@tak:~$ ls
... ls output ...
zengargoyle@tak:~$ exit
logout
Connection to tak closed.
I would guess that the password input is accepting the "\r" as an input terminator (because login/password type input is wonky like that) but the proper input terminator for the type of session input and for general shell commands is "\n".
Just a guess, unless your Solaris is wonky or running some special shell (not csh/sh/etc) you should be using "\n". I've done a bunch of Expect stuff with Solaris, routers, switches, ... over ssh and never have I used "\r". I always use "\n" and have never had the sort of problem you seem to be having. | [reply] [Watch: Dir/Any] [d/l] |
Yes, I was just posting the resolution. You are absolutely correct! I just discovered that Solaris 8 likes to have it's responses and commands terminated with \n and not \r. I actually have used \r for connecting to network appliances and never had a problem.
What threw me off was I sent the user login password as "$passw\r" and it worked ok. I have updated all my send commands to use \n instead of \r. All is well now. Thanks!!
| [reply] [Watch: Dir/Any] |