标签:利用perl模块发邮件
vim sendmail.pl #!/usr/bin/perl -w use MIME::Lite; sub perl_sendmail { my $mail_to=shift; #my $mail_to="$_[0]"; my $from=shift; #my $from = "$_[1]"; my $subject=shift; #my $subject = "$_[2]"; my $data=shift; #my $data = "$_[3]"; $sendmail = MIME::Lite->new( From => $from, To => $mail_to, Subject => $subject, Data => $data ); $sendmail->attr("content-type" => "text/html"); $sendmail->send; } perl_sendmail(@ARGV); vim databases.sh #!/bin/bash OP_MAILBOX="hello@qq.com,amos.lu@qq.com" phone_lu=15800329316 phone_xia=15121132075 [ -d /tmp/db ] || mkdir /tmp/db function database() { local data_file vale num vale=60 data_file="/tmp/php_db.log" while read line do num=`echo $line|awk -F‘=‘ ‘{print $2}‘` title=`echo $line|awk -F‘]‘ ‘{print $2}‘|awk ‘{print $1}‘` [ -f /tmp/db/$title ] && content=`cat /tmp/db/$title` && ret=`echo $content|awk -F‘=‘ ‘{print $2}‘` if [ "x$num" != "x" -a $num -lt $vale ] then echo "$title=1" > /tmp/db/$title sendmailx "$line <br>一小时检测一次,连续报警两次,请通知以下运维人员<br>卢李明:$phone_lu<br>夏志培:$phone_xia" "数据异常" elif [ "x$content" != "x" ] then if [ $ret -eq 1 -a $num -gt $vale ] then echo "$title=0" > /tmp/db/$title sendmailx "$line <br>这是恢复邮件,您可以安心休息了。" "数据恢复" fi fi done < $data_file } function sendmailx() { local mail_msg mail_from mail_msg=$1 mail_title=$2 mail_from="skymobi@sky-mobi.com" for mailbox in `echo $OP_MAILBOX|sed ‘s/,/ /g‘` do /path/to/sendmail.pl "$mailbox" "$mail_from" "$mail_title" "$mail_msg" sleep 0.5 done } database
本文出自 “秋风颂” 博客,请务必保留此出处http://qiufengsong.blog.51cto.com/7520243/1424616
标签:利用perl模块发邮件
原文地址:http://qiufengsong.blog.51cto.com/7520243/1424616