Skip to content

Instantly share code, notes, and snippets.

@ywatase
Created July 10, 2012 09:55
Show Gist options
  • Save ywatase/3082394 to your computer and use it in GitHub Desktop.
Save ywatase/3082394 to your computer and use it in GitHub Desktop.
#!/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 Getopt::Long;
use Sys::Hostname qw(hostname);
my $to = '[email protected]';
my $from = 'mha@' . hostname;
#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 );
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
use Email::MIME;
use Email::MIME::Creator;
use Email::Sender::Simple qw(sendmail);
use Log::Dispatch;
my $log = Log::Dispatch->new(
outputs => [
[
'Syslog',
min_level => 'info',
ident => 'mha'
]
]
);
$log->log(level => 'critical', message => $body );
my $email = Email::MIME->create(
header_str => [
From => $from,
To => $to,
Subject => $subject,
],
attributes => {
content_type => 'text/plain',
charset => 'UTF-8',
encoding => 'base64',
},
body_str => $body,
);
eval {
sendmail( $email);
};
if ($@) {
$log->log(level => 'error', message => "fail to send mail: $@");
};
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment