当少于10 GB 时,发送邮件提醒
1: import smtplib
2: import string
3: import os
4: import time
5:
6: def sendmail(dirname):
7: SUBJECT = "Email test from me!"
8: FROM = "[email protected]"
9: TO = "[email protected]"
10: text = "磁盘满了,请清理数据"+dirname
11: BODY = "From: "+FROM+'\r\n'+"To: "+TO+'\r\n'+"Subject: "+SUBJECT+'\r\n'+""+"\r\n"+text+"\r\n"
12: server = smtplib.SMTP('smtp.163.com',25)
13: server.login('id','passwd')
14: server.sendmail(FROM,TO,BODY)
15: server.quit()
16:
17: if "__main__"==__name__:
18: path = "/home"
19: st = os.statvfs(path)
20: while(1):
21: free = (st.f_bavail * st.f_frsize)
22: if free <; 10*1024*1024*1024 :
23: sendmail(path)
24: time.sleep(73)