Answer the question
In order to leave comments, you need to log in
Why sometimes broken data comes through Net::Telnet in perl ?
There is a script. Opens a session with the server, sends commands, receives the output of these commands in response, parses something and gets the number of lines. perl ./test.pl all 192.168.0.1 23 001,002,003
the composition of the command depends on the number of the last argument, in which the data is separated by a comma, each block before the comma is a separate command. in this case, 3 telnet commands will be sent to the server.
stat #001001000
stat #001002000
stat #001003000
#!/usr/bin/perl
use Net::Telnet;
use Switch;
$type = $ARGV[0];
$ipats = $ARGV[1];
$port = $ARGV[2];
$stream = $ARGV[3];
@streams = split(',', $stream);
switch($type){
case "one" { $reg="one"; }
case "two" { $reg="two"; }
case "three" { $reg="three"; }
case "other" { $reg="one|two|three"; }
case "all" { $reg=".*"; }
}
$swi = new Net::Telnet (Host => $ipats ,Port => $port , Timeout => 20, Prompt => '/>$/');
foreach $str (@streams) {
chomp $str;
@output = $swi->cmd(String => 'stat #001'.$str.'000');
foreach $resultline (@output) {
if ($resultline =~ m/state=\"($reg)\"/ ) {
push @arr, $1;
#chomp $resultline;print $resultline." ".$str."\n";
}
}
}
print "". @arr."\n";
#print scalar(@arr);
$swi->close();
Answer the question
In order to leave comments, you need to log in
Net::Telnet needs a bit of patching. I won’t give a link, because I’m greedy (but Google doesn’t).
Another option is not to patch, but to set waitfor more, prompt is always valid and correct.
As a means - in the block where we accept, we specify waitfor additionally.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question