Linux 发邮件磁盘空间监控(python)
作者:mdxy-dxy 时间:2022-03-15 09:17:24
核心代码:
#!/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()
标签:python,磁盘空间监控
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python生成随机数的方法详解(最全)
2023-05-04 12:36:08
![](https://img.aspxhome.com/file/2023/5/71355_0s.png)
asp error对象基础
2008-08-04 13:25:00
MSSQL数据库排序规则如何更改
2023-07-01 11:09:58
Python中print函数简单使用总结
2022-08-07 19:28:36
![](https://img.aspxhome.com/file/2023/8/64728_0s.png)
关于redux-saga中take使用方法详解
2023-08-06 00:54:11
xhtml+css VS div+css
2008-04-07 13:00:00
python快速建立超简单的web服务器的实现方法
2021-03-14 23:25:14
XML:OpenSearch 浏览器指定搜索应用
2010-05-04 19:37:00
![](https://img.aspxhome.com/file/UploadPic/20105/4/2008101720221064077801-78s.png)
asp生成一个不重复的随机数字
2007-09-12 19:12:00
Python多进程之进程同步及通信详解
2022-01-07 00:29:13
![](https://img.aspxhome.com/file/2023/9/71299_0s.png)
python 实现绘制整齐的表格
2022-09-25 05:51:22
![](https://img.aspxhome.com/file/2023/1/72211_0s.jpg)
支持中文的Len, Left, Right函数
2008-03-18 13:50:00
PHP伪静态页面函数附使用方法
2023-11-22 06:25:42
asp如何制作一个防止多次刷新计数的图片计数器?
2010-06-29 21:28:00
python实现简单多人聊天室
2022-08-17 15:04:13
![](https://img.aspxhome.com/file/2023/7/67887_0s.jpg)
4行Python代码生成图像验证码(2种)
2021-02-08 06:08:03
![](https://img.aspxhome.com/file/2023/9/76909_0s.png)
thinkPHP5.0框架简单配置作用域的方法
2023-11-14 10:24:51
全方位清理浮动
2009-06-16 14:51:00
Python爬虫之网页图片抓取的方法
2021-12-19 00:47:20
![](https://img.aspxhome.com/file/2023/3/78523_0s.png)
Asp性能优化之Response.IsClientConnected属性及其应用示例
2008-09-18 12:13:00