溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

PYTHON測(cè)試腳本怎么寫(xiě)

發(fā)布時(shí)間:2021-12-04 16:52:59 來(lái)源:億速云 閱讀:199 作者:柒染 欄目:互聯(lián)網(wǎng)科技

PYTHON測(cè)試腳本怎么寫(xiě),針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。

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

#檢查數(shù)據(jù)庫(kù)進(jìn)程是否正常運(yùn)行,如果不正常運(yùn)行,將輸出相關(guān)進(jìn)程失敗信息,后面的檢查信息將停止進(jìn)行。
#如果運(yùn)行正常,說(shuō)明數(shù)據(jù)庫(kù)是可用的,繼續(xù)后面信息的檢查。
#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()


#檢查數(shù)據(jù)庫(kù)監(jiān)聽(tīng)是否正常運(yùn)行,如果不正常運(yùn)行,將發(fā)出警告信息,如果沒(méi)有警告信息說(shuō)明監(jiān)聽(tīng)運(yùn)行正常。
#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()



#檢查數(shù)據(jù)庫(kù)是否可以連接,如果不能連接,將發(fā)出警告信息(not open or not connect)
#如果沒(méi)有警告信息說(shuō)明監(jiān)聽(tīng)運(yùn)行正常。
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

關(guān)于PYTHON測(cè)試腳本怎么寫(xiě)問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識(shí)。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI