Perl 传值问题
时间:2010-10-20
来源:互联网
本帖最后由 mitmax 于 2010-10-20 10:12 编辑
这个是监控Mysql主从的现在只能监控一台,比如我还有很多台,这3个值如果依次传给account.
my $host = '192.168.1.203','192.168.1.204','192.168.1.205';
my $user = 'myrepl',myrepl1',myrepl3',;
my $pass = '123456','123456','123456';
复制代码
这个是监控Mysql主从的现在只能监控一台,比如我还有很多台,这3个值如果依次传给account.
my $host = '192.168.1.203','192.168.1.204','192.168.1.205';
my $user = 'myrepl',myrepl1',myrepl3',;
my $pass = '123456','123456','123456';
- #!/usr/bin/perl -w
- # Use mandatory external modules
- use strict;
- use DBI;
- use Net::SMTP_auth;
- use Time::HiRes;
- use POSIX "strftime";
-
- my $host = '192.168.1.203';
- my $user = 'myrepl';
- my $pass = '123456';
- my $port = '3306';
- my $max_behind_m = 120;
- my $check_log = '/var/log/mysql_check_log';
-
- my $mailhost = 'smtp.163.com';
- my $mailfrom = '[email protected]';
- my @mailto = '[email protected]';
- my $subject = "mysql_repl_error::$host";
- my $text;
- my $mailuser = 'xxxxx';
- my $mailpasswd = 'xxxxxx';
-
- # open log--file
- open FH, ">> $check_log" or die $!;
-
- # connect to servers (this)
- sub account {
- my ($host, $port, $user, $pass)=@_;
- my $this_dbh = &MysqlConnect( $host, $port, $user, $pass );
- print FH "ERROR: Can't connect to MySQL (host = $host:$port, user = $user)!"
- if ( !$this_dbh );
- }
-
-
- # Get slave info
- my $slave_status = &MysqlQuery( $this_dbh, "SHOW SLAVE STATUS" );
- print FH "ERROR: SQL Query Error: " . $this_dbh->errstr unless ($slave_status);
-
- my $Slave_IO = $slave_status->{Slave_IO_Running};
- my $Slave_SQL = $slave_status->{Slave_SQL_Running};
- my $Seconds_Behind_Master = $slave_status->{Seconds_Behind_Master};
-
- print "IO:\t\t $Slave_IO\n";
- print "SQL:\t\t $Slave_SQL\n";
- print "Behind_Master:\t $Seconds_Behind_Master\n";
-
- # Send to Mail
- if ( ( $Slave_IO eq 'Yes' ) and ( $Slave_SQL eq 'Yes' ) and ( $Seconds_Behind_Master < $max_behind_m ) ) {
- print "mysql replicate is OK" . "\n";
- }
- else {
- print FH "-" x 80 . ">", "\n";
- my $start_time = ¤t_time();
- print FH "start at $start_time\n";
-
- print FH "mysql replicate is Fail!!!!!!!!!!!!" . "\n";
- print FH "IO:\t\t $Slave_IO\n";
- print FH "SQL:\t\t $Slave_SQL\n";
- print FH "Behind_Master:\t $Seconds_Behind_Master\n";
-
- my $end_time = ¤t_time();
- print FH "end at $end_time\n";
- close (FH);
-
- $text = "$Slave_IO, $Slave_SQL, $Seconds_Behind_Master";
- &SendMail();
- }
-
- #-----------------------------------------------------------------
- sub MysqlConnect {
- my ( $host, $port, $user, $pass ) = @_;
- my $dsn = "DBI:mysql:host=$host;port=$port";
- return DBI->connect( $dsn, $user, $pass, { PrintError => 0 } );
- }
-
- #-----------------------------------------------------------------
- sub MysqlQuery {
- my ( $dbh, $query ) = @_;
- my $sth = $dbh->prepare($query);
- my $res = $sth->execute;
- return undef unless ($res);
- my $row = $sth->fetchrow_hashref;
- $sth->finish;
- return $row;
- }
-
-
- #-----------------------------------------------------------------
- sub current_time() {
- my $time_now = POSIX::strftime("[%Y-%m-%d %H:%M:%S]", localtime);
- return $time_now;
- }
-
-
- #-----------------------------------------------------------------
- sub SendMail() {
-
- my $smtp = Net::SMTP_auth->new( $mailhost, Timeout => 120, Debug => 1 )
- or die "Error.\n";
- $smtp->auth( 'LOGIN', $mailuser, $mailpasswd );
-
- foreach my $mailto (@mailto) {
- $smtp->mail($mailfrom);
- $smtp->to($mailto);
- $smtp->data();
- $smtp->datasend("To: $mailto\n");
- $smtp->datasend("From:$mailfrom\n");
- $smtp->datasend("Subject: $subject\n");
- $smtp->datasend("\n");
- $smtp->datasend("$text\n");
- $smtp->dataend();
- }
-
- $smtp->quit;
- }
作者: mitmax 发布时间: 2010-10-20
看看顶楼提问的智慧。
作者: 兰花仙子 发布时间: 2010-10-20
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28