2016-07-07 53 views
0

通常我使用Python,但我有一个Perl项目。那么:将snmpwalk的结果指向字符串的过程是什么?我想搜索字符串以查看它是否包含较小的字符串。perl snmpwalk到字符串

这是我到目前为止有:

foreach (@list){ 
     chomp($_); 
     system("snmpwalk -v 2c -c community-string $_ oid-hidden"); 
     if (index($string, $substring) != -1) { 
      print "'$string' contains '$substring'\n"; 
     } 

} 
+2

我会推荐使用一个模块,或者[Net :: SNMP](https://metacpan.org/pod/Net: :SNMP),纯Perl模块或[SNMP.pm](http://www.net-snmp.org/docs/perl-SNMP-README.html),Perl绑定到net-snmp库。 – ThisSuitIsBlackNot

回答

2

system函数不返回函数输出,使用qx//或反引号,所以你的电话snmpwalk的行会是这样的:

my $output = qx/snmpwalk -v 2c -c community-string $_ oid-hidden/;

然后你用你需要的输出变量做什么,更多信息我会推荐你​​http://perldoc.perl.org/perlop.html#Quote-Like-Operators

但是,在更一般的术语中,我会遵循@ThisSuitIsBlackNot的评论中的建议...