• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Linux 发邮件磁盘空间监控(python)

Linux 发邮件磁盘空间监控(python)

作者:mdxy-dxy 字体:[增加 减小] 来源:互联网

mdxy-dxy 通过本文主要向大家介绍了linux查看磁盘空间,linux磁盘分区,linux扩展磁盘空间,linux清理磁盘空间,linux查看磁盘分区等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

核心代码:

#!/usr/bin/python
# -*- coding: UTF-8 -*-


import smtplib
import os
import commands,time 
from email.mime.text import MIMEText
#from email import MIMEText
disk_free=os.popen('df -lh')
list_disk=disk_free.read()
mailto_list=["2880329185@qq.com","2881280685@qq.com","2880089704@qq.com","2880329180@qq.com"]
mail_host="smtp.139.com" 
mail_user="user"  
mail_pass="password"  
mail_postfix="jljgl@.com" 
use01=commands.getstatusoutput("df -lh|awk '{print $4}'|grep '%'|awk -F '%' '{print $1}'|grep -v Use")
use02=commands.getstatusoutput("df -lh|awk '{print $5}'|grep '%'|awk -F '%' '{print $1}'|grep -v Use")
getrecord=commands.getstatusoutput("cat /home/oracle/script/mail.log|awk '{print $1}'")
gettime=commands.getstatusoutput("cat /home/oracle/script/mail.log|awk '{print $2}'")


free01=use01[1]
free02=use02[1]+'\n'+use01[1]
new_time=time.strftime("%Y%m%d", time.localtime())


def send_mail(to_list,sub,content):
  me=mail_postfix
  msg = MIMEText(content,_subtype='plain',_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 SyntaxError:
    pass
    return False
if __name__ == '__main__':
    if free02>30:
        id=0
        if new_time>gettime[1]:
            while 1:
                getrecord=commands.getstatusoutput("cat /home/oracle/script/mail.log|awk '{print $1}'")
                id=id+1
                '''
                jl=open('/home/oracle/script/dd.log')
                record=jl.read()
                '''
                line_l=str(id)+' '+new_time




                df=open('/home/oracle/script/mail.log','w')
                df.writelines(line_l)
                df.close()
                
                if send_mail(mailto_list,"hello",list_disk):
                    print "发送成功"
                else:
                    print "发送失败"
                if getrecord[1]>0:
                    break
        else:
            line_m=str(0)+' '+new_time
            free=open('/home/oracle/script/mail.log','w')
            free.writelines(line_m)
            free.close()
</div>

</div>

您可能想查找下面的文章:

  • Linux 发邮件磁盘空间监控(python)

相关文章

  • 跟老齐学Python之编写类之二方法
  • windows系统下Python环境搭建教程
  • Python中使用pprint函数进行格式化输出的教程
  • 低版本中Python除法运算小技巧
  • Python3使用requests包抓取并保存网页源码的方法
  • Python简单检测文本类型的2种方法【基于文件头及cchardet库】
  • 完美解决python遍历删除字典里值为空的元素报错问题
  • python中requests模块的使用方法
  • 如何解决django配置settings时遇到Could not import settings 'conf.local'
  • 剖析Python的Tornado框架中session支持的实现代码

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Django与遗留的数据库整合的方法指南
    • pytyon 带有重复的全排列
    • python实现根据用户输入从电影网站获取影片信息的方法
    • python类定义的讲解
    • python类继承用法实例分析
    • 使用Python的PIL模块来进行图片对比
    • Python中的with...as用法介绍
    • django接入新浪微博OAuth的方法
    • Python标准库urllib2的一些使用细节总结
    • python使用xlrd实现检索excel中某列含有指定字符串记录的方法

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有