Chinaunix首页 | 论坛 | 博客
  • 博客访问: 330542
  • 博文数量: 53
  • 博客积分: 1132
  • 博客等级: 少尉
  • 技术积分: 451
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-18 14:22
文章分类

全部博文(53)

文章存档

2014年(1)

2013年(11)

2012年(17)

2011年(16)

2010年(8)

分类: PERL

2012-12-14 16:12:40

 采用 SMTP_auth 模块发送从mysql中取出的访问量。
#!/bin/env perl
use DBI;
use POSIX;
use Net::SMTP_auth;
use MIME::Base64;
use strict;
my ($date,$wday,$Dtime,$Day,$dbh,$sth,$sth_E4,$smtp,%hash,@list)=(localtime)[3,6];
if($wday =~ /0/){
    exit;
}elsif($date =~ /1/){
    $Dtime = (strftime ("%Y-%m",localtime(time-86400)))."-01";
    $Day = strftime ("%Y-%m-%d",localtime);
}else{
    $Dtime = (strftime ("%Y-%m",localtime))."-01";
    $Day = strftime ("%Y-%m-%d",localtime);
}

$dbh = DBI->connect("DBI:mysql:host=192.168.11.1","root","123456") || die "Could not connect to database: $DBI::errstr";
my @database=('Site','Site4.0');
foreach(@database){
    $sth = $dbh->prepare(qq{select date_format(create_time,'%Y-%m-%d'),visit_count from `$_`.tbl_site_record_by_daily where create_time>=? and create_timeexecute($Dtime,$Day);
    while(my ($add_data,$value) = $sth->fetchrow_array()){
        my $result = sprintf("%.2f",$value/10000)."万";
        if(exists $hash{$add_data}){
            $hash{$add_data} .= "\t$result\n";
        }else{
            $hash{$add_data} .= "$result";
        }
    }
}
$sth->finish();
$dbh->disconnect();

foreach(reverse sort keys %hash){
    push @list,"$_tt$hash{$_}";
}
$smtp = Net::SMTP_auth->new('mail.b.com',
                Timeout => 30,
                Hello => 'mail.b.com',
                Debug => 0);

$smtp->auth('LOGIN','pv@b.com','123456');
$smtp->mail('pv@b.com ');
$smtp->to('a@b.com','b@b.com','c@b.com');

$smtp->data();
$smtp->datasend("From: =?utf-8?B?".encode_base64("访问量统计",'')."?= \n");
$smtp->datasend("To: a@b.com\n");
$smtp->datasend("Cc: b@b.com;c@b.com\n");
$smtp->datasend("Content-Type:text/plain;ChartSet=GB2312;");
$smtp->datasend("Content-Transfer-Encoding:base64\n");
$smtp->datasend("Mime-Version: 1.0\n");
$smtp->datasend("Subject: $Day 访问量统计\n");
$smtp->datasend("\n");
$smtp->datasend("访问量统计($Dtime ~ $Day)\n");
$smtp->datasend("\t\t\tsite 3.0\tsite 4.0\n");
$smtp->datasend(@list);
$smtp->datasend("\n");
$smtp->dataend();
$smtp->quit;

阅读(1274) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~