oracle awr script,python脚本自动生成ORACLE AWR报告

#!/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'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值