开始使用nagios
时对于perl
不太了解,在搜索到sendEmail
后,这款工具使用相同的简单 ./sendEmail -f
发送邮件地址 -t
接收邮件地址 -s
发送邮件的SMTP
服务地址 -u
标题 -xu
用户名 -xp
用户密码 m
发送内容 ;现在开始学习使用perl
相关知识了,了解相关perl
模块安装后开始着手使用gmail
免费邮发送邮件,因为gmail
免费邮都是使用ssl
加密的,发送时需带-o tls=yes
选项都知道是是使用ssl
了就选择yes
了,
其它免费邮如tom,126
的好像不行 ./sendEmail -f mlnagios@gmail.com -t qwujhq@126.com -u "this is title" -m "this is my first to mail you " -s smtp.gmail.com -xu mlnagios -xp 34 -o tls=yes
Jul 17 01:25:35 localhost sendEmail[20965]: ERROR => No TLS support! SendEmail can't load required libraries. (try installing Net::SSLeay and IO::Socket::SSL)
这个错误,下面来动手安装下perl
相关模块吧,我这里讲是利用cpan
下载相关模块然后把模块放到相关perl
路径下安装,当然你也可以在第一次使用cpan
时设定cpan
的路径,我这人比较懒,一路回车过去了,因为我这里只是想要这两个包传到别的地方去安装。 [root@localhost Net-SSLeay-1.35]# perl -MCPAN -e shell
command argument description
a,b,d,m WORD or /REGEXP/ about authors, bundles, distributions, modules
i WORD or /REGEXP/ about anything of above
r NONE reinstall recommendations
ls AUTHOR about files in the author's directory
Download, Test, Make, Install...
test MODULES, make test (implies make)
install DISTS, BUNDLES make install (implies test)
look open subshell in these dists' directories
readme display these dists' README files
h,? display this menu ! perl-code eval a perl command
o conf [opt] set and query options q quit the cpan shell
reload cpan load CPAN.pm again reload index load newer indices
autobundle Snapshot force cmd unconditionally do cmd
cpan> get IO::Socket::SSL
我这个是下好了再次使用下载命令时会提示你已经在下载目录下有了 cpan> get IO::Socket::SSL
Going to read /root/.cpan/Metadata
Database was generated on Tue, 28 Jul 2009 00:27:00 GMT
Running get for module IO::Socket::SSL
CPAN: Digest::MD5 loaded ok
Checksum for /root/.cpan/sources/authors/id/S/SU/SULLR/IO-Socket-SSL-1.27.tar.gz ok
[root@localhost sendEmail-v1.55]# cd /root/.cpan/sources/authors/id/S/SU/SULLR/
[root@localhost SULLR]# ls
CHECKSUMS IO-Socket-SSL-1.27.tar.gz
好了,两包都下好了,把相关传你想在哪台机器上实现发mail
功能 我这里是/usr/lib/perl5/5.8.5/
这些模块的安装就比较简单了,使用more
查看安装帮助 [root@localhost Net-SSLeay-1.35]# more README
这是Net::SSLeay
的后面perldoc
应该可以明白吧 ./Makefile.PL -t # builds and tests it
make install # You probably have to su to root to do this
perldoc Net::SSLeay # optional, but highly recommended
perldoc Net::SSLeay::Handle
[root@localhost Net-SSLeay-1.35]# ./Makefile.PL -t
Cannot determine perl version info from lib/Net/SSLeay.pm
Cannot determine license info from lib/Net/SSLeay.pm
*** Found OpenSSL-0.9.7a installed in /usr
*** Be sure to use the same compiler and options to compile your OpenSSL, perl,
and Net::SSLeay. Mixing and matching compilers is not supported.
Do you want to run external tests?
These tests *will* *fail* if you do not have network connectivity. [n] y
Writing Makefile for Net::SSLeay
[root@localhost Net-SSLeay-1.35]# make install
[root@localhost sendEmail-v1.55]# pwd
[root@localhost sendEmail-v1.55]# ./sendEmail -f mlnagios@gmail.com -t qwujhq@126.com -u "this is title" -m "this is my first to mail you " -s smtp.gmail.com -xu mlnagios -xp 1234 -o tls=yes
Jul 21 13:17:04 localhost sendEmail[10764]: Email was sent successfully!
# 'notify-host-by-email' command definition
command_name notify-host-by-email
command_line /usr/local/bin/sendEmail/sendEmail -f mlnagios@gmail.com -t $CONTACTEMAIL$ -s smtp.gmail.com -xu mlnagios -xp 34 -o tls=yes -u "****** Nagios ******" -m " ** $NOTIFICATIONTYPE$ Service Alert: $HOSTNAME$/$HOSTADDRESS$ is $HOSTSTATE$ at \n\nDate/Time: $LONGDATETIME$ Additional Info:$HOSTOUTPUT$"
# 'notify-service-by-email' command definition
command_name notify-service-by-email
command_line /usr/local/bin/sendEmail/sendEmail -f mlnagios@gmail.com -t $CONTACTEMAIL$ -s smtp.gmail.com -xu mlnagios -xp 34 -o tls=yes -u " ****** Nagios ****** " -m " ** $NOTIFICATIONTYPE$ Service Alert: $HOSTNAME$/$HOSTADDRESS$ $SERVICEDESC$ is $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$ Additional Info:$SERVICEOUTPUT$ $CONTACTPAGER$"
数据库相关字段通知脚本,如下取得数据库相关脚本,然后发邮件通知相关联系人 field=`mysql -uroot --password=xxxxxx <<QUERY_SQL
select last from qeedoo.tbl_sch_account where email="test1";
for mail in "jairus@xxx.com qwujhq@xx.com heaventxxx@xxx.com"
/usr/local/bin/sendEmail/sendEmail -f mlnagios@gmail.com -t $mail -s smtp.gmail.com -xu mlnagios -xp xxx -o tls=yes -u " ****** THE NOTICE FOR MYSQL ****** " -m "$field"
最后自己定义下crontab
定时查询一下,如果需要更智能些自己调整,呵呵,sendEmail可以从这里下载http://caspian.dotconf.net/menu/Software/SendEmail/ 本文转自 qwjhq 51CTO博客,原文链接:http://blog.51cto.com/bingdian/184372