CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Facing Problem with Perl Expect, if the command length is slightly longer is splitting into 2-3 lines with garbage

 



abhishekrc2007
New User

May 21, 2014, 10:43 AM

Post #1 of 2 (33338 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 ........


Code
$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();



Laurent_R
Veteran / Moderator

May 22, 2014, 1:54 PM

Post #2 of 2 (32778 views)
Re: [abhishekrc2007] Facing Problem with Perl Expect, if the command length is slightly longer is splitting into 2-3 lines with garbage [In reply to] Can't Post

First a disclaimer: I have never used the Expect Perl module and can't help you on that.

Otherwise, it seems that you have a default terminal line-length problem, not really a Perl problem. This might be a simple configuration issue, but I do not have enough information on your system to suggest corrections (assuming I could, which is far from guaranteed).

One possible work-around is to reduce the length of your command line through the use of Unix environment variables.

Rather than firing a command like this:

Code
 "cat /opt/telorb/axe/loadingGroup01_1/Outage/OutageReport* | tail -2"

you might do something like this in your shell:

Code
export PATH /opt/telorb/axe/loadingGroup01_1/Outage/ 
cat ${PATH}OutageReport* | tail -2"

I have no idea whether this will work in your case, but I think it is worth trying.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives