我很难找到为什么我的perl脚本没有正确处理输出.
所以,代码(根据建议的更改更新):
sub telnet_connection{
my $targetHost = $_[0];
#my $uname = $_[1];
#my $pword = $_[2];
my @listOfCommands = @{$_[3]};
if($verbose){print "\t\tAttempting telnet connection to $targetHost\n"; }
eval{
$telnet = Net::Telnet->new( Timeout=>5, Errmode=>'return', dump_log=>"dump_log.txt", input_log=>"input_log.txt");
$telnet->open($targetHost);
$telnet->waitfor('/Username: $/i');
$telnet->print($username);
$telnet->waitfor('/PASSCODE: $/i');
$telnet->print($password);
$telnet->waitfor('/\>/');
#for(my $j=0; $j le scalar @listOfCommands; $j++)
for my $command (@listOfCommands)
{
if($verbose) { print "\t\tClient: " . $targetHost . " Command: $command\n"; }
if($verbose) { print "\t\tExecuting command: $command\n"; }
my @output = $telnet->cmd($command); …
Run Code Online (Sandbox Code Playgroud)