Linux發郵件磁碟空間監控
Linux發郵件磁碟空間監控
#!/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()
#!/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()
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29065182/viewspace-1985855/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- linux 下監控磁碟空間Linux
- 自動監控Oracle 表空間資訊併傳送郵件指令碼Oracle指令碼
- 用 Linux Shell 指令碼來監控磁碟使用情況併傳送郵件Linux指令碼
- 伺服器磁碟監控指令碼分享(含報警郵件)伺服器指令碼
- Linux-使用snmp監控郵件佇列Linux佇列
- 將Outlook中的郵件儲存到本地磁碟,釋放郵箱空間
- [linux]磁碟監控程式並且發EMailLinuxAI
- 表空間郵件預警(luckyfriends)
- SAP BW 郵件傳送監控策略
- 關於郵件監控的問題
- oracle表空間增加監控Oracle
- 監控硬碟空間指令碼硬碟指令碼
- sqlserver監控指令碼_發現某個等待就發出郵件SQLServer指令碼
- linux 發郵件Linux
- 監控oracle表空間指令碼Oracle指令碼
- 表空間監控(三)tablespace detailAI
- oracle空間使用監控指令碼Oracle指令碼
- Linux 檢視磁碟空間大小Linux
- linux 獲取磁碟空間大小Linux
- 磁碟IO效能監控(Linux 和 Windows)LinuxWindows
- zabbix監控linux磁碟io的模板Linux
- 給Oracle BIGFILE表空間增加磁碟(通用的LINUX增加磁碟空間方案)OracleLinux
- 表空間監控(二)datafile size detailAI
- AIX分頁(交換)空間的監控AI
- Nodejs監控Apple召回計劃&郵件提醒NodeJSAPP
- zabbix監控之同時向多人郵件報警
- html格式郵件監控failures大於0的jobHTMLAI
- linux檢視剩餘磁碟空間Linux
- nagios監控linux磁碟io的bugiOSLinux
- linux通過cacti監控apache通過飛信郵件進行報警LinuxApache
- oracle監控表空間,JOB,rman備份Oracle
- Linux 磁碟掛載和swap空間管理Linux
- linux檢視mysql佔用磁碟空間LinuxMySql
- linux mail利用外部郵箱地址發郵件LinuxAI
- Linux系統監控之磁碟I/O篇Linux
- 在Linux中,如何進行磁碟效能監控?Linux
- linux下發郵件的配置Linux
- 監控和管理Oracle UNDO表空間的使用Oracle