为什么我无法在Ubuntu 18.04上安装Perl Net-SNMP

问题描述 投票:1回答:2

我正在尝试将Perl Net-SNMP用于Ubuntu 18.04上的某些监控脚本。 但是当我执行Perl脚本时,它说:Can't locate SNMP.pm in @INC (you may need to install the SNMP module).

我尝试了所有可能的方法来安装Perl Net-SNMP,但无法成功安装。 以下是我尝试在Ubuntu 18.04上安装Perl Net-SNMP的命令:

sudo apt-get install perl-net-snmp
sudo apt-get install net-snmp

我甚至尝试使用从以下网站下载的tar球[net-snmp_5.7.3+dfsg.orig.tar.xz]的tar球安装:Here

寻求积极的帮助摆脱这一点。 此问题以前没有问过,所以请在标记为重复之前做好研究。

我的Perl脚本:

#!/usr/bin/perl
use warnings;
use strict;
use SNMP;
use Socket;

# VARIABLES YOU SHOULD EDIT.
my $comm = 'public';    # EDIT ME!
my $dest = 'localhost'; # EDIT ME!
my $mib  = 'sysDescr';  # Toy with this to get different
                        # results.
my $sver = '2';         # EDIT ME!

# VARIABLES YOU SHOULD LEAVE ALONE.
my $sess; # The SNMP::Session object that does the work.
my $var;  # Used to hold the individual responses.
my $vb;   # The Varbind object used for the 'real' query.

# Initialize the MIB (else you can't do queries).
&SNMP::initMib();

my %snmpparms;
$snmpparms{Community} = $comm;
$snmpparms{DestHost} = inet_ntoa(inet_aton($dest));
$snmpparms{Version} = $sver;
$snmpparms{UseSprintValue} = '1';
$sess = new SNMP::Session(%snmpparms);

# Turn the MIB object into something we can actually use.
$vb = new SNMP::Varbind([$mib,'0']); # '0' is the instance.

$var = $sess->get($vb); # Get exactly what we asked for.
if ($sess->{ErrorNum}) {
  die "Got $sess->{ErrorStr} querying $dest for $mib.\n";
  # Done as a block since you may not always want to die
  # in here.  You could set up another query, just go on,
  # or whatever...
}
print $vb->tag, ".", $vb->iid, " : $var\n";

# Now let's show a MIB that might return multiple instances.
$mib = 'ipNetToMediaPhysAddress'; # The ARP table!
$vb = new SNMP::Varbind([$mib]);  # No instance this time.

# I prefer this loop method.  YMMV.
for ( $var = $sess->getnext($vb);
      ($vb->tag eq $mib) and not ($sess->{ErrorNum});
      $var = $sess->getnext($vb)
    ) {
  print $vb->tag, ".", $vb->iid, " : ", $var, "\n";
}
if ($sess->{ErrorNum}) {
  die "Got $sess->{ErrorStr} querying $dest for $mib.\n";
}

exit;

完成错误:

Can't locate SNMP.pm in @INC (you may need to install the SNMP module) (@INC contains: /home/prak/perl5/lib/perl5/5.26.1/x86_64-linux-gnu-thread-multi /home/prak/perl5/lib/perl5/5.26.1 /home/prak/perl5/lib/perl5/x86_64-linux-gnu-thread-multi /home/prak/perl5/lib/perl5 /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /home/prak/perl5/lib/perl5/5.26.0 /home/prak/perl5/lib/perl5/5.26.0/x86_64-linux-gnu-thread-multi /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at snmp1.pl line 4.
BEGIN failed--compilation aborted at snmp1.pl line 4.
perl ubuntu-18.04 net-snmp
2个回答
4
投票

尝试sudo apt-get install libsnmp-perl然后只需从CPAN安装SNMP作为CPAN SNMP.


3
投票

您需要安装的软件包称为libnet-snmp-perl。 Debian和相关发行版上的Perl模块包的名称始终以lib开头,以-perl结尾。

您安装的文件是一组SNMP实用程序,而不是Perl模块。

© www.soinside.com 2019 - 2024. All rights reserved.