偶尔有空上来看看
分类: python/ruby
2019-03-11 23:36:12
import cx_oracle
with open("conn.txt", "r") as f:
for line in f.readlines():
line = line.strip('\n') #去掉列表中每一个元素的换行符
print(line)
conn = cx_oracle.connect(line)
cursor = conn.cursor()
sql = "select owner,db_link,username, " \
" host from dba_db_links where owner<>'sys' and db_link<>'sys_hub' "
cursor.execute(sql)
one = cursor.fetchall()
for x in one:
print (line,x)
cursor.close()
conn.close()
把上述脚本存为dl_link.py,然后用python 3执行
手工粘贴吧,直接把结果放到excel还不会...
将sql语句改为其他的也可,例如查询某个参数都是什么...
-------------------------------------------------------------------------
取每个数据库大小
import cx_oracle
with open("conn2.txt", "r") as f:
for line in f.readlines():
line = line.strip('\n')
#print(line)
conn = cx_oracle.connect(line)
cursor = conn.cursor()
sql = "select trunc(sum(bytes)/1024/1024/1024) g from dba_data_files"
cursor.execute(sql)
one = cursor.fetchall()
for x in one:
print (line,x[0],'g')
cursor.close()
conn.close()
import cx_oracle
with open("conn3.txt", "r") as f:
for line in f.readlines():
line = line.strip('\n') #去掉列表中每一个元素的换行符
l=line.split(',')
#conn = cx_oracle.connect(l[1]) #取连接串
conn=cx_oracle.connect(l[1],l[2],l[3])
cursor = conn.cursor()
sql = "select username from dba_users where account_status='open' order by 1 "
cursor.execute(sql)
one = cursor.fetchall()
f=open("user1.txt","a")
for x in one:
print (l[3],",",l[0],",",x[0],file=f)
cursor.close()
conn.close()
print("i got it.")