前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python 检查目录零字节文件并发送邮件

python 检查目录零字节文件并发送邮件

作者头像
葫芦
发布2019-04-17 14:33:59
6160
发布2019-04-17 14:33:59
举报
文章被收录于专栏:葫芦
代码语言:javascript
复制
#encoding=gb2312
'''
Created on 2016年4月11日

@author: wangzi
'''

import smtplib
from email.mime.text import MIMEText
import time
import re

mailto_list = ['123@qq.com','234@qq.com']
mail_host = 'mail.server.com'
mail_user = '123'
mail_pass = '123'
mail_postfix='qq.com'
def send_mail(to_list,sub,content):
    me = '王梓'+'<'+mail_user+'@'+mail_postfix+'>'
    msg = MIMEText(content,_subtype = 'html',_charset='gb2312')
    msg['Subject'] = sub
    msg['From'] = me

    msg['to'] = ';'.join(to_list)

    try:
        server = smtplib.SMTP()
        server.connect(mail_host)
        server.login(mail_user,mail_pass)
        server.sendmail(me,to_list,msg.as_string())
        server.close()
        return True
    except Exception as e:
        print (e)
        return False
import os
if __name__ == '__main__':
    warning = '基地,同事好:<br> <DD>  如下日志0字节,请检查谢谢。</DD><br>'
    warning_init = warning
    path = ('/logcenter02/data/backup_data/base/base_book/')
    for path,dir,files in os.walk(path):
        matchfile = filter(lambda filterfile:not re.match('a_b-updated.*|i_b-statistics.*|a_b-author.*|a_b-catalog.*|a_b-package.*|a_b-book.*|bookorder.*|catalogorder.*|i_b-rankmonth.*|i_b-ranktotal.*|i_b-rankweek.*',filterfile),files)
        sorted_matchfile = sorted(matchfile)
        for file in sorted_matchfile:
            check_file = os.path.join(path,file)
            if  os.stat(check_file).st_size == 0:
                warning += '<span style="color:#E53333;">%s</span> 大小为 <span style="color:#E53333;">%s</span>,请检查!<br>'% (file,os.stat(check_file).st_size)
    check_time = time.strftime('%Y%m%d',time.localtime(time.time()))
    if warning != warning_init:
        if send_mail(mailto_list, '%s 阅读基地0字节日志统计。' % (check_time), warning):
            print('%s 基地发送成功' % (check_time) )
        else:
            print('%s 基地发送失败'  % (check_time))
    else:
        print("%s 基地无0字节日志" % (check_time))
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016/04/11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档