缺少输出线

时间:2014-11-13 08:15:20

标签: perl

我已经编写了一个小程序来获取路由器的输出。但输出文件中缺少输出的起始内容。

#!C:\strawberry\perl\bin\perl -w  
open ( OUTPUT,"> D:\\Routerbkp\\router\\abc.txt" );    
use Control::CLI;                                            
# Create the object instance for SSH                 
$cli = new Control::CLI('SSH');                      
# Connect to host - Note that with SSH,              
#  authentication is part of the connection process  
$cli->connect(  Host            => '10.0.0.1',       
                Username        => 'abc',        
                Password        => 'abc',        
                PrivateKey      => 'C:\Users\Administrator\.ssh\key_10.0.0.1_22.pub',    

             );                                      
# Send a command and read the resulting output  
$output1  = $cli->cmd("terminal length 0");
sleep(1);         
$output2  = $cli->cmd("show running-config");
sleep(5);                       
$output8  = $cli->cmd("show alarm current");
sleep(2);

$cli->disconnect;                   
print OUTPUT $output1;
print OUTPUT $output2;
print OUTPUT $output8;

1 个答案:

答案 0 :(得分:0)

如果您的代码出现问题,您的第一个停靠点始终是use strict;use warnings;。 然后 - 修复那个open语句。尝试以下方式:

open ( my $output_fh, ">", "D:\\Routerbkp\\router\\abc.txt" ) or die $!;

您可能还希望捕获$cli -> connect()中的任何错误,因为无法保证其有效。

my $result = $cli -> connect ( ...

if ( not $result ) { print "Connect failed: ", $cli -> errormode(), ":", $cli -> errormsg(), "\n"; };
相关问题