Chinaunix首页 | 论坛 | 博客
  • 博客访问: 360895
  • 博文数量: 86
  • 博客积分: 1460
  • 博客等级: 上尉
  • 技术积分: 848
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-12 14:07
文章分类

全部博文(86)

文章存档

2017年(36)

2016年(17)

2015年(1)

2013年(12)

2012年(2)

2011年(1)

2010年(1)

2009年(16)

我的朋友

分类: Python/Ruby

2013-12-31 08:52:27

  1. #!/usr/bin/python
  2. #coding=gbk
  3. #2011-08-12
  4. import os
  5. import sys
  6. import smtplib
  7. import pickle
  8. import mimetypes
  9. from email.MIMEText import MIMEText
  10. from email.MIMEImage import MIMEImage
  11. from email.MIMEMultipart import MIMEMultipart
  12. SMTP_SERVER='localhost'
  13. #EMAIL_USER='root'
  14. #EMAIL_PASSWD=''
  15. EMAIL_SUBJECT='dg01.com.cn AWR Report'
  16. FROM_USER='root@dg01.com.cn'
  17. TO_USERS=['vcdog@126.com','kevin@hotmail.com']
  18. def createawr():
  19.   pipe = os.popen(' su - oracle -c "/u01/oracle/product/10.2.0/db_1/bin/sqlplus /nolog @awrrpt.sql"')
  20.   print 'create awr report is ok!'
  21. def mysendmail(fromaddr,toaddrs,subject):
  22.         COMMASPACE=','
  23.         msg = MIMEMultipart()
  24.         msg['From'] = fromaddr
  25.         msg['To'] = COMMASPACE.join(toaddrs)
  26.         msg['Subject'] = subject
  27.         txt = MIMEText("172.21.1.30 AWR Report, The report be send at 9 AM every day ")
  28.         msg.attach(txt)
  29.         fileName = r'/home/oracle/awr.html'
  30.         ctype, encoding = mimetypes.guess_type(fileName)
  31.         if ctype is None or encoding is not None:
  32.             ctype = 'application/octet-stream'
  33.         maintype, subtype = ctype.split('/', 1)
  34.         att = MIMEImage((lambda f: (f.read(), f.close()))(open(fileName, 'rb'))[0], _subtype = subtype)
  35.         att.add_header('Content-Disposition', 'attachment', filename = fileName)
  36.         msg.attach(att)
  37.         server=smtplib.SMTP(SMTP_SERVER)
  38.         #server.login(EMAIL_USER,EMAIL_PASSWD)
  39.         server.sendmail(fromaddr,toaddrs,msg.as_string())
  40.         server.quit()
  41. if __name__=='__main__':
  42.                 createawr()
  43.                 mysendmail(FROM_USER, TO_USERS, EMAIL_SUBJECT)
  44.                 print 'send successful'
阅读(2596) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~