2016-07-07 50 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的評論中的建議...