PYTHON测试脚本怎么写,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
#!/usr/bin/python
# -*- coding: UTF-8 -*-
#CHECK ORACLE
SID="tcbjeas"
CHECK_LOG_FILE="tcbjeas.out"
FLAG=0
import os
my_file='/tmp/out.txt'
if os.path.exists(my_file):
#删除文件,可使用以下两种方法。
os.remove(my_file)
#检查数据库进程是否正常运行,如果不正常运行,将输出相关进程失败信息,后面的检查信息将停止进行。
#如果运行正常,说明数据库是可用的,继续后面信息的检查。
#check pmon process
import os
run=os.popen("ps -ef |grep ora_pmon_$SID |grep -v grep|wc -l").read()
if "0" in run:
FLAG=1
f=open("out.txt","w")
try:
f.write('WARNING!!!ora_pmon_$SID!process is not running!'+'\n')
finally:
f.close()
#check smon process
import os
run=os.popen("ps -ef |grep ora_smon_$SID |grep -v grep|wc -l").read()
if "0" in run:
FLAG=1
f=open("out.txt","a")
try:
f.write('WARNING!!!ora_smon_$SID!process is not running!'+'\n')
finally:
f.close()
#check dbwr process
import os
dbwr=os.popen("ps -ef |grep ora_dbw0_$SID |grep -v grep|wc -l").read()
if "0" in dbwr:
FLAG=1
f=open("out.txt","a")
try:
f.write('WARNING!!!ora_dbw0_$SID!process is not running!'+'\n')
finally:
f.close()
#check lgwr process
import os
lgwr=os.popen('ps -ef |grep ora_lgwr_$SID |grep -v grep|wc -l').read()
if "0" in lgwr:
print "lgwr"
FLAG=1
f=open("out.txt","a")
try:
f.write('WARNING!!!ora_lgwr_$SID!process is not running!'+'\n')
finally:
f.close()
if FLAG==1:
f=open("out.txt","a")
try:
f.write('Warning!!!Oracle Instance $SID Is Down!'+'\n')
finally:
f.close()
else:
f=open("out.txt","a")
try:
f.write('OK,Oracle Process Are Running Normal!'+'\n')
finally:
f.close()
#检查数据库监听是否正常运行,如果不正常运行,将发出警告信息,如果没有警告信息说明监听运行正常。
#check listener
import os
listen=os.popen("$ORACLE_HOME/bin/lsnrctl status|grep -i 'Instance'|grep -v grep|wc -l").read()
if "0" in listen:
f=open("out.txt","a")
try:
f.write('Warning!!! Listener is not running normal!'+'\n')
finally:
f.close()
else:
f=open("out.txt","a")
try:
f.write('OK,Listener is running normal!'+'\n')
finally:
f.close()
#检查数据库是否可以连接,如果不能连接,将发出警告信息(not open or not connect)
#如果没有警告信息说明监听运行正常。
import os
os.popen('sh sql.sh')
import os
connect=os.popen("grep -i 'OPEN' /tmp/sql.txt|grep -v grep|wc -l").read()
if "1" in connect:
f=open("out.txt","a")
try:
f.write('OK,Oracle Connect Normal!'+'\n')
finally:
f.close()
else:
f=open("out.txt","a")
try:
f.write('Warning!!Database Is Not Open'+'\n')
finally:
f.close()
cat sql.sh
#!/bin/bash
sqlplus user/passwd@orcl<< EOF
spool /tmp/sql.txt
set lines 500
select status from v\$instance;
spool off
exit
EOF
关于PYTHON测试脚本怎么写问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。