- #!/usr/bin/python
- #coding=gbk
- #2011-08-12
- 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_USER='root'
- #EMAIL_PASSWD=''
- 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.login(EMAIL_USER,EMAIL_PASSWD)
- server.sendmail(fromaddr,toaddrs,msg.as_string())
- server.quit()
- if __name__=='__main__':
- createawr()
- mysendmail(FROM_USER, TO_USERS, EMAIL_SUBJECT)
- print 'send successful'
阅读(2596) | 评论(0) | 转发(0) |