-
-
-
-
import os
-
import sys
-
import smtplib
-
import pickle
-
import mimetypes
-
from email.MIMEText import MIMEText
-
from email.MIMEImage import MIMEImage
-
from email.MIMEMultipart import MIMEMultipart
-
SMTP_SERVER='localhost'
-
-
-
EMAIL_SUBJECT='dg01.com.cn AWR Report'
-
FROM_USER='root@dg01.com.cn'
-
TO_USERS=['vcdog@126.com','kevin@hotmail.com']
-
def createawr():
-
pipe = os.popen(' su - oracle -c "/u01/oracle/product/10.2.0/db_1/bin/sqlplus /nolog @awrrpt.sql"')
-
print 'create awr report is ok!'
-
def mysendmail(fromaddr,toaddrs,subject):
-
COMMASPACE=','
- msg = MIMEMultipart()
-
msg['From'] = fromaddr
-
msg['To'] = COMMASPACE.join(toaddrs)
-
msg['Subject'] = subject
-
txt = MIMEText("172.21.1.30 AWR Report, The report be send at 9 AM every day ")
- msg.attach(txt)
-
fileName = r'/home/oracle/awr.html'
- ctype, encoding = mimetypes.guess_type(fileName)
-
if ctype is None or encoding is not None:
-
ctype = 'application/octet-stream'
-
maintype, subtype = ctype.split('/', 1)
-
att = MIMEImage((lambda f: (f.read(), f.close()))(open(fileName, 'rb'))[0], _subtype = subtype)
-
att.add_header('Content-Disposition', 'attachment', filename = fileName)
- msg.attach(att)
- server=smtplib.SMTP(SMTP_SERVER)
-
- server.sendmail(fromaddr,toaddrs,msg.as_string())
- server.quit()
-
if __name__=='__main__':
- createawr()
- mysendmail(FROM_USER, TO_USERS, EMAIL_SUBJECT)
-
print 'send successful'
本文转自vcdog 51CTO博客,原文链接:http://blog.51cto.com/255361/837936,如需转载请自行联系原作者