zoukankan      html  css  js  c++  java
  • perl 监控数据变化

    !/usr/bin/perl

    use strict;

    use DBI;
    use HTTP::Date qw(time2iso str2time time2iso time2isoz);
    use Net::SMTP;
    sub send_mail{
    if (@_ != 2){print “请输入2个参数 ”;exit 1};
    (m,n) = @_; #将参数赋值给变量
    my toaddress=m;
    my CurrTime=time2iso(time());myto_address = $m;

    my mailuser=zhaoyangjian@zjcap.cn;mymail_pwd = ‘xxxxxx’;
    my $mail_server = ‘smtp.exmail.qq.com’;

    my $from    = "From: $mail_user
    ";
    my $subject = "Subject: zjcap info
    ";
    my $info = "$CurrTime--$n";
     my $message = <<CONTENT; 
     $info
    

    CONTENT
    my smtp=Net::SMTP>new(mail_server);

    $smtp->auth($mail_user, $mail_pwd) || die "Auth Error! $!";
    $smtp->mail($mail_user);
    $smtp->to($to_address);
    
    $smtp->data();             # begin the data
    $smtp->datasend($from);    # set user
    $smtp->datasend($subject); # set subject
    $smtp->datasend("
    
    ");
    $smtp->datasend("$message
    "); # set content
    $smtp->dataend();
    $smtp->quit();
    

    }
    my dbName=oadb;mydbUser = ‘query’;
    my dbUserPass=query;mydbh = DBI->connect("dbi:Oracle:dbName,dbUser, dbUserPass)ordiecantconnecttodatabase;mysql = “select count(*) from VXSPACE.FORMMAIN_1530”;
    my sth=dbh->prepare($sql);

    $sth->execute();

    my var=sth->fetchrow_array();
    print “$var is $var ”;

    读取上一次文件

    #
    open( A, “<”, “count.txt” );
    while () {
    count=_;
    };
    print “上次记录的记录数为$count ”;

    最新的文件记录数 写入count.txt

    open( B, “>”, “count.txt” );
    print B (“$var ”);

    if ( defined(count)  &&var != count &&var !=0 ){
    print “开始处理 ”;
    my sql=selectstartdate,field0001from(selectfromvxspace.FORMMAIN1530aorderby4desc)whererownum<2;mysth = dbh>prepare(sql);
    sth>execute();while(my@arr=sth->fetchrow_array()){
    print “@arr ”;send_mail(‘zhaoyangjian@zjcap.cn’,”@arr ”)

    }

    }

  • 相关阅读:
    数据库sql一些常考基础命令
    C# and .NET之父——传奇的anders hejlsberg
    数据库中3大范式的详解
    小胖求职记—求职中的技巧
    程序员们喜爱看的文章
    为什么世界上没有天才(转)
    C语言中system函数的使用
    关于DataGrid的知识和技巧
    分页
    在调用方法时产生异常的处理方法
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351323.html
Copyright © 2011-2022 走看看