自动化监控多个Oracle表空间
上节讲了如何利用Python自动监控Oracle表空间使用率
这节会利用一个循环一次性查询多个表空间使用率
环境设置
Linux系统为 Centos 6.8
Python环境为 Python 3.6
orale信息文件
其次建立一个新的文本文件存放多个数据库的信息
注意最后一行不能是空白行
文件名称:/home/oracle/script/oracle_list.txt
10.65.1.120 sys sys_password 1521 dctest
10.60.14.70 sys sys_password 1527 np1
最终程序
文件名称:/home/oracle/script/checktablespace_multiple.py
#!/usr/bin/python
#coding=utf8
import cx_Oracle
from sendmail_phone import *
def oraclesql(cursor):
#这里我们使用python的open方法打开文件并读取文件内容作为SQL语句执行
#可使用绝对路径或相对路径
fp=open('/home/oracle/script/tablespace.sql','r')
#fp=open('./tablespace.sql','r')
fp1=fp.read()
cursor.execute(fp1)
data=cursor.fetchall()
return data
if __name__==&