码迷,mamicode.com
首页 > 其他好文 > 详细

mha邮件提醒的send_report脚本

时间:2020-05-27 01:25:21      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:war   pos   getopt   odi   get   copy   sts   mysq   app   

send_report脚本中需要修改的也没几处, 如下, 都已经标注出来了

[root@rd-mysql-test4 mha]# cat /usr/local/bin/send_report 
#!/usr/bin/perl
 
#  Copyright (C) 2011 DeNA Co.,Ltd.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#  Foundation, Inc.,
#  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
## Note: This is a sample script and is not complete. Modify the script based on your environment.
 
use strict;
use warnings FATAL => ‘all‘;
use Mail::Sender;
use Getopt::Long;
 
#new_master_host and new_slave_hosts are set only when recovering master succeeded
my ( $dead_master_host, $new_master_host, $new_slave_hosts, $subject, $body );
 
my $smtp=‘smtp.163.com‘;  # 这里的smtp可以查看要使用的邮箱的smtp值, 或者百度
my $mail_from=‘from@163.com‘;  # 填写邮箱
my $mail_user=‘from@163.com‘;  # 填写邮箱
my $mail_pass=‘password‘;  # 注意这里的密码是邮箱开启smtp服务时设定的密码, 不是邮箱的登陆密码
#my $mail_to=[‘to1@qq.com‘,‘to2@qq.com‘];
my $mail_to=‘to@qq.com‘;  # 接受邮件的邮箱
 
GetOptions(
  ‘orig_master_host=s‘ => \$dead_master_host,
  ‘new_master_host=s‘  => \$new_master_host,
  ‘new_slave_hosts=s‘  => \$new_slave_hosts,
  ‘subject=s‘          => \$subject,
  ‘body=s‘             => \$body,
);
 
# Do whatever you want here
mailToContacts($smtp,$mail_from,$mail_user,$mail_pass,$mail_to,$subject,$body);
 
sub mailToContacts {
    my ($smtp, $mail_from, $mail_user, $mail_pass, $mail_to, $subject, $msg ) = @_;
    open my $DEBUG, ">/var/log/masterha/app1/mail.log"  # 这里的路径需要修改,改成一个真是存在的路径即可
        or die "Can‘t open the debug    file:$!\n";
    my $sender = new Mail::Sender {
        ctype        => ‘text/plain;charset=utf-8‘,
        encoding    => ‘utf-8‘,
        smtp        => $smtp,
        from        => $mail_from,
        auth        => ‘LOGIN‘,
        TLS_allowed    => ‘0‘,
        authid        => $mail_user,
        authpwd        => $mail_pass,
        to        => $mail_to,
        subject        => $subject,
        debug        => $DEBUG
    };
    $sender->MailMsg(
        {
            msg => $msg,
            debug => $DEBUG
        }
    ) or print $Mail::Sender::Error;
    return 1;
}
 
exit 0;

 

mha邮件提醒的send_report脚本

标签:war   pos   getopt   odi   get   copy   sts   mysq   app   

原文地址:https://www.cnblogs.com/quzq/p/12969754.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!