zoukankan      html  css  js  c++  java
  • Python遍历目录下所有文件的最后一行进行判断若错误及时邮件报警-案例

    遍历目录下所有文件的最后一行进行判断若错误及时邮件报警-案例:

    #-*- encoding: utf-8 -*-
    __author__ = 'liudong'
    
    import linecache,sys,time,datetime,os
    import urllib,sys,urllib,json,smtplib
    from email.mime.text import MIMEText
    
    mailto_list=['liudong@philisense.com']
    mail_host="smtp.philisense.com"
    mail_user="liudong@philisense.com"
    mail_pass="邮箱密码"
    mail_postfix="philisense.com"
    def send_mail(to_list,sub,content):
         me="hello"+"<"+mail_user+"@"+mail_postfix+">"
         msg = MIMEText(content,_subtype='plain')
         msg['Subject'] = sub
         msg['From'] = me
         msg['To'] = ";".join(to_list)
         try:
             server = smtplib.SMTP(mail_host,25)
             server.set_debuglevel(1)
             server.login(mail_user,mail_pass)
             server.sendmail(me, to_list, msg.as_string())
             server.close()
         except :
             return False
    
    for root,dirs,files in os.walk(r'/home/work/app/jppt/log/new_log'):
        for file in files:
            with open(root+"/"+file, 'r') as f:
                lines = f.readlines()
                last_line = lines[-1]
                a = last_line.strip()
                try:
                    timeArray = time.strptime(a,"%Y-%m-%d %H:%M:%S")
                    timeStamp = int(time.mktime(timeArray))
                except Exception,ex:
                    send_mail(mailto_list,'jppt','file = '+ file + '
    ' + '
    ' + a)
  • 相关阅读:
    H5软键盘搜索
    ios顺畅滑动
    自定义滚动条样式
    mockjs模拟数据(本地版)
    移动端防止窗体滚动
    css超出部分省略号
    H5自带的type=date或者month等日期控件移动端显示placeholder
    判断是否在微信内打开
    滚动加载数据
    activemq 5.6 连接池的内存泄露问题
  • 原文地址:https://www.cnblogs.com/liuyansheng/p/6206680.html
Copyright © 2011-2022 走看看