
abhishekrc2007
New User
May 21, 2014, 10:43 AM
Post #1 of 2
(40148 views)
|
Facing Problem with Perl Expect, if the command length is slightly longer is splitting into 2-3 lines with garbage
|
Can't Post
|
|
Hi, i'm using below code to take health checks for different servers, but I'm getting garbage output in log file, for example : if I fire command "cat /opt/telorb/axe/loadingGroup01_1/Outage/OutageReport* | tail -2" in log file it is coming as Proc_m0_s13$ cat /opt/telorb/axe/loadingGroup01_1/Outage/OutageReport* | tail <b/axe/loadingGroup01_1/Outage/OutageReport* | tail -2 Please help me to overcome this problem ........
$exp = new Expect; $exp->restart_timeout_upon_receive(1); $exp->spawn("ssh -l $nodeuser $ip\r"); $exp->log_file("$logpath/$node_name/$node_name.log", "w"); $exp->expect($timeout, ['-re', 'Password:',sub{ $exp->send("$nodepass\r"); } ], ['-re', 'password:',sub{ $exp->send("$nodepass\r"); } ]); # $exp->send("$nodepass\r"); $exp->expect($timeout,"*"); # $exp->notransfer(1); $exp->expect($timeout, [ timeout => sub { die "login Time Out\n"; } ], [ '-re', "$prompt", sub { my $self = shift; foreach my $priority (sort {$a<=>$b} keys %priority_commands) { my %all_commands = %{$priority_commands{$priority}}; foreach my $commands (keys %all_commands) { $self->clear_accum(); $self->restart_timeout_upon_receive(1); $commands =~ s/[\r\n]//g; $self->send("$commands\n") ; sleep 2; while(1){ sleep(1); $self->expect( [ qr/MORE/i,sub{ $self->send_slow(" "); exp_continue; } ], ['-re', "$prompt",{ last } ]); } sleep 2; } } } ], [ eof => sub { die "ERROR: could not spawn SSH.\n"; } ] ); # $exp->clear_accum(); $exp->expect($timeout,$prompt); $exp->send("exit\n"); $exp->log_file(undef); $exp->soft_close();
|