Hi,
I am facing issues with using Expect.pm for ssh login. In certain
cases I find that the command is
not sent fully to the server or it is sent without the trailing "\r"
or "\n" characters. This is observed
with long commands( 60 to 100 chars). Is there any issue with expect
not sending full command
or "\r" "\n" characters over a period of time.
My script is doing following steps :
1. Login to server using ssh
2. execute aroung 10 commands in loop.
3. Every time I execute command I look for server prompt. And if
prompt is found then I execute next command.
If prompt is not found then my script waits indefinitely
Note : All the commands are of length between 60 to 100 characters.
Sample script:
use Expect;
my $exp = new Expect;
$exp->spawn("ssh -l root $filer_ip") or die "Cannot spawn : $!\n";
my @commands =("cmd1", "cmd2", "cmd3");
while(1) {
$i=0;
$count=@commands;
while($count>0) {
(undef,$error,undef, $before_match,undef)=$exp->expect($timeout,$prompt);
$exp->clear_accum();
print "\n\n## Command executed with output:\n $before_match \n##\n\n";
if ($before_match =~ /$prompt/) {
$exp->send("$commands[$i]\r");
$count--;
$i++;
} else {
$exp->clear_accum();
print("Prompt not found");
while(1){}
}
}
}
Are there any issues with my script ?
Regards,
Yatin
|