Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2155952
  • 博文数量: 195
  • 博客积分: 4378
  • 博客等级: 上校
  • 技术积分: 4046
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-09 11:37
个人简介

白天和黑夜只交替没交换无法想像对方的世界

文章分类

全部博文(195)

文章存档

2014年(3)

2013年(20)

2012年(18)

2011年(107)

2010年(17)

2009年(5)

2008年(20)

2007年(5)

分类: Python/Ruby

2011-08-31 18:54:01

  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'
阅读(6248) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~