找出日志文件中错误行并发送邮件
脚本功能:
读取/var/log/messages(也可以是其他日志文件)日志文件,从里面找出error或者warn的行,然后发送邮件。
第一次读取的时候,会记录读取的位置,下次读取的时候会从上次读取的位置的开始读取,如果没有发现error或warn行,则不发邮件
脚本使用说明:
1.需要的Perl模块
Net::SMTP //perl自带,不用安装
Socket //perl自带,不用安装
Sys::Hostname //perl自带,不用安装
Authen::SASL (用使来验证邮件用户名和密码) //需要安装
使用root身份用如下命令来安装Authen::SASL模块:
[root@server ~]# cpan Authen::SASL
If you do not want to enter a dialog now, you can answer 'no' to this
question and I'll try to autoconfigure. (Note: you can revisit this
dialog anytime later by typing 'o conf init' at the cpan prompt.)
Are you ready for manual configuration? [yes] no //如果有该步骤的话,选择no,自动配置
Checking if your kit is complete...
Looks good
Warning: prerequisite Digest::HMAC_MD5 0 not found.
Warning: prerequisite ExtUtils::MakeMaker 6.42 not found. We have 6.30.
Writing Makefile for Authen::SASL
---- Unsatisfied dependencies detected during [G/GB/GBARR/Authen-SASL-2.15.tar.gz] -----
Digest::HMAC_MD5
ExtUtils::MakeMaker
Shall I follow them and prepend them to the queue
of modules we are processing right now? [yes] yes
Running make install
Installing /usr/lib/perl5/site_perl/5.8.8/Authen/SASL.pm
Installing /usr/lib/perl5/site_perl/5.8.8/Authen/SASL.pod
Installing /usr/lib/perl5/site_perl/5.8.8/Authen/SASL/Perl.pm
Installing /usr/lib/perl5/site_perl/5.8.8/Authen/SASL/Perl.pod
Installing /usr/lib/perl5/site_perl/5.8.8/Authen/SASL/EXTERNAL.pm
Installing /usr/lib/perl5/site_perl/5.8.8/Authen/SASL/CRAM_MD5.pm
Installing /usr/lib/perl5/site_perl/5.8.8/Authen/SASL/Perl/DIGEST_MD5.pm
Installing /usr/lib/perl5/site_perl/5.8.8/Authen/SASL/Perl/PLAIN.pm
Installing /usr/lib/perl5/site_perl/5.8.8/Authen/SASL/Perl/ANONYMOUS.pm
Installing /usr/lib/perl5/site_perl/5.8.8/Authen/SASL/Perl/LOGIN.pm
Installing /usr/lib/perl5/site_perl/5.8.8/Authen/SASL/Perl/GSSAPI.pm
Installing /usr/lib/perl5/site_perl/5.8.8/Authen/SASL/Perl/EXTERNAL.pm
Installing /usr/lib/perl5/site_perl/5.8.8/Authen/SASL/Perl/CRAM_MD5.pm
Installing /usr/share/man/man3/Authen::SASL::Perl.3pm
Installing /usr/share/man/man3/Authen::SASL::Perl::LOGIN.3pm
Installing /usr/share/man/man3/Authen::SASL::Perl::CRAM_MD5.3pm
Installing /usr/share/man/man3/Authen::SASL::Perl::ANONYMOUS.3pm
Installing /usr/share/man/man3/Authen::SASL.3pm
Installing /usr/share/man/man3/Authen::SASL::Perl::EXTERNAL.3pm
Installing /usr/share/man/man3/Authen::SASL::Perl::GSSAPI.3pm
Installing /usr/share/man/man3/Authen::SASL::Perl::PLAIN.3pm
Installing /usr/share/man/man3/Authen::SASL::Pe
rl::DIGEST_MD5.3pm
Appending installation info to /usr/lib/perl5/5.8.8/i386-linux-thread-multi/perllocal.pod
/usr/bin/make install -- OK 看