文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>CheckExpireAccount(用户账号过期检查)

CheckExpireAccount(用户账号过期检查)

时间:2010-08-14  来源:linscora

 

#!/usr/bin/perl -w

use Date::Calc qw/Delta_Days/;
use Net::SMTP;
use Net::SMTP_auth;
use MIME::Base64;

@userlist = `cat /etc/passwd|awk -F: '{if(\$3>=500&&\$3<=1000)print \$1}'`;
foreach (@userlist) {
        $username = "$_";
        chomp($username);
        print "User processed is $username", "\n";
        $expireStr = `chage -l $username |awk -F':' '/Account/{print \$2}'`;
        userDateLeft($expireStr);
}

if ( $mailContent ) {
        print "The mail body is: ", "$mailContent", "\n";
        MailtoSmtp($mailContent);
}

sub userDateLeft {
        $dateexpire = $expireStr;
        $dateexpire =~ s/^\s+//;
        chomp($dateexpire);
        $monstring = (split(' ', $dateexpire))[0];
        if ( $monstring ne "never" ) {
                $monstring = (split(' ', $dateexpire))[0];
                $chdaystring = (split(',', (split(' ', $dateexpire))[1]))[0];
                $yearstring = (split(' ', $dateexpire))[2];
                #$wholedate1 = "$monstring\-$chdaystring\-$yearstring";

                %months = (
                        Jan => '01', Feb => '02', Mar => '03', Apr => '04',
                        May => '05', Jun => '06', Jul => '07', Aug => '08',
                        Sep => '09', Oct => '10', Nov => '11', Dec => '12',
                );
                $Digmon = "$months{$monstring}";
                $wholedate2 = "$Digmon\-$chdaystring\-$yearstring";
                print "The whole date is $wholedate2", "\n";
                print "The month is $Digmon", "\n";
                $oldYear = $yearstring;
                $oldMon = $Digmon;
                $oldDate = $chdaystring;
                $currYear = `date +%Y`;
                $currMon = `date +%m`;
                $currDate = `date +%d`;
                $daysDif = Delta_Days( $currYear, $currMon, $currDate, $oldYear, $oldMon, $oldDate);
                if ( $daysDif <= 10) {
                        $mailContent .= "The $username account has $daysDif days left\n";
                }
                #print "The mail body is: ", "$mailContent", "\n";

        }
}

sub MailtoSmtp {
        $mail_server = 'smtp.example.com';
        $mail_from = 'user1@example.com';
        $mail_to = 'user2@example.com';
        $uname = 'user1';
        $passwd = 'password';
        $mailtitle = 'account availability';
        # Debug Mode

        $smtp = Net::SMTP->new("$mail_server" , Debug => 1);
        # Normal Mode

        #$smtp = Net::SMTP->new("$mail_server" );

        $smtp->auth("$uname", "$password");
        $smtp->mail("$mail_from");
        $smtp->to("$mail_to");
        $smtp->data();
        $smtp->datasend("Content-Type:text/plain;charset=GB2312\n");
        $smtp->datasend("Content-Transfer-Encoding:base64\n");
        $smtp->datasend("From:$mail_from \n");
        $smtp->datasend("To:$mail_to \n");
        $smtp->datasend("Subject:=?gb2312?B?".encode_base64($mailtitle,'')."?=\n\n");
        $smtp->datasend("\n");
        $smtp->datasend(encode_base64($mailContent,'')." \n");
        $smtp->dataend();
        $smtp->quit;
}


相关阅读 更多 +
排行榜 更多 +
永劫无间怎么赠送别人礼物

永劫无间怎么赠送别人礼物

冒险解谜 下载
抹茶交易所app最新版

抹茶交易所app最新版

金融理财 下载
阿克里危机手机版下载

阿克里危机手机版下载

飞行射击 下载