2013-03-03 42 views
0

我正在编写一个脚本,通过保存输出“show run”来保存开关配置,因为固件在通过tftp工作时遇到问题。 “show run”的输出除以帖子More: <space>, Quit: q, One line: <return>perl telnet - 如何处理多个页面的输出

foreach (@linksys_sps){ 
    print ("Connecting to ",$_,"\n"); 
    my $telnet = new Net::Telnet (Timeout=>10,Errmode=>'return'); 
    $telnet->open($_); 
    if ($telnet->errmsg){ 
    print "Can't connect to " . $_ . " Error: " . $telnet->errmsg . "\n"; 
    } else { 
    $telnet->waitfor('/User Name:$/i'); 
    $telnet->print('admin'); 
    $telnet->waitfor('/Password:$/i'); 
    $telnet->print('password'); 
    my @lines = $telnet->cmd("sh run"); 
    print @lines; 
    sleep(5); 
    $telnet->print('exit'); 
    } 
} 

和他的工作结果:

# sh run 
no spanning-tree 
interface port-channel 1 
shutdown 
exit 
interface port-channel 2 
shutdown 
exit 
interface port-channel 3 
shutdown 
exit 
interface port-channel 4 
shutdown 
exit 
interface port-channel 5 
shutdown 
exit 
interface port-channel 6 
shutdown 
exit 
interface port-channel 7 
shutdown 
exit 
More: <space>, Quit: q, One line: <return> 

我下面的脚本的一部分

# sh run 
no spanning-tree 
interface port-channel 1 
shutdown 
exit 
interface port-channel 2 
shutdown 
exit 
interface port-channel 3 
shutdown 
exit 
interface port-channel 4 
shutdown 
exit 
interface port-channel 5 
shutdown 
exit 
interface port-channel 6 
shutdown 
exit 
interface port-channel 7 
shutdown 
exit 
More: <space>, Quit: q, One line: <return> 

如何解决呢?

回答

1

在您的开关上是否有选项将页面长度设置为零(0)?如果是这样,你必须在执行'sh run'命令之前添加它。

+0

问题解决 – 2013-03-04 10:05:39

0

阿尔卡特6224和同戴尔的PowerConnect 3548它的工作原理:

my @lines = $telnet->cmd("terminal datadump"); 
@lines = $telnet->cmd("show run");