首页 电脑 电脑学堂 查看内容

python脚本自动生成ORACLE AWR报告

2012-12-31 15:46 702 0

摘要: #!/usr/bin/python #coding=gbk #2011-08-12 import os  import sys  import smt...
关键词: nbsp email import SERVER fileName SUBJECT MIMEMultipart msg Report MIMEImage

#!/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='[email protected]' TO_USERS=['[email protected]','[email protected]']  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'
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部