代码改变世界

Perl 脚本报Can't locate Mail/Sender.pm 解决办法

2014-05-11 23:54  潇湘隐者  阅读(10003)  评论(0编辑  收藏  举报

    在新的Linux Server(Red Hat Enterprise Linux Server release 5.7 (Tikanga))上配置磁盘空间告警的perl脚本后,测试时报如下错误

[oracle@DB-Server scripts]$ ./disk_capatiy_alarm.sh

Can't locate Mail/Sender.pm in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /home/oracle/scripts/output/disk_sendmail.pl line 2.

BEGIN failed--compilation aborted at /home/oracle/scripts/output/disk_sendmail.pl line 2.

Perl脚本disk_sendmail.pl 如下所示,其中使用了Mail-Sender邮件模块,

   1: #!/usr/bin/perl
   2: use Mail::Sender;
   3: $sender = new Mail::Sender {smtp => 'xxx.xxx.xxx.xxx', from => 'xxx@xxx.com'};
   4: $sender->MailFile({to => 'xxx@xxx.com',
   5: cc=>'xxx@xxx.com ',
   6: subject => 'The server xxxx\'s Disk Capacity Alarm',
   7: msg => 'Dear All,
   8:    The server xxxx disk capacity alarm ,please take action for it. many thanks!
   9: ',
  10: file => '/home/oracle/scripts/output/diskdetail.txt'});

出现这个错误是因为Perl没有安装Mail-Sender模块,安装了此模块问题即可解决,Mail::Sender模块支持发送带附件的邮件。可以使用下面几种方式安装

1:使用cpan安装,要求服务器能够访问外网,否则无法下载相关包。

    cpan> install Mail::Sender

2:下载perl-Mail-Sender-0.8.16-1.el5.pp.noarch.rpm

    下载地址:http://rpm.pbone.net/index.php3/stat/4/idpl/10370607/dir/redhat_el_5/com/perl-Mail-Sender-0.8.16-1.el5.pp.noarch.rpm.html

  [root@DB-Server oracle]# rpm -ivh perl-Mail-Sender-0.8.16-1.el5.pp.noarch.rpm 
warning: perl-Mail-Sender-0.8.16-1.el5.pp.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 6971f6ac
Preparing...                ########################################### [100%]
   1:perl-Mail-Sender       ########################################### [100%]

3: 下载安装Mail-Sender-0.8.16.tar.gz 。这种方法我没有实验过,因为http://search.cpan.org/CPAN/authors/id/J/JE/JENDA/Mail-Sender-0.8.16.tar.gz 老是无法下载这个安装包。