abhishekrc2007 has asked for the wisdom of the Perl Monks concerning the following question:

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_co +mmands) { 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();

it seems that it is a default terminal line-length problem, not really a Perl problem ........... So, can anyone please guide me to how I'll increase the terminal width ....... <\p>

Thanks in advance .....

  • Comment on Facing Problem with Perl Expect, if the command length is slightly longer is splitting into 2-3 lines with garbage
  • Download Code

Replies are listed 'Best First'.
Re: Facing Problem with Perl Expect, if the command length is slightly longer is splitting into 2-3 lines with garbage
by igelkott (Priest) on May 27, 2014 at 17:36 UTC
    default terminal line-length problem

    I don't really understand how you got that mangled line in your log but you could try to have the session match your local line-length with:

    $exp->slave->clone_winsize_from(\*STDIN);

    If that doesn't work, try sending a direct command like: stty columns 144