Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to write PYTHON test script

Shulou Source: shulou.com Published: 2022-06-01 17:55:48 09月20日 Update

PYTHON test script how to write, in response to this problem, this article details the corresponding analysis and solution, hoping to help more want to solve this problem of small partners to find a simpler and easier way.

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

#Delete files in two ways.

os.remove(my_file)

#Check whether the database process is running normally. If it is not running normally, the relevant process failure information will be output, and the following check information will be stopped.

#If it works correctly, the database is available, continue to check the following information.

#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 whether database monitoring is running normally. If it is not running normally, a warning message will be issued. If there is no warning message, the monitoring is running normally.

#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()

#Check whether the database can be connected, if it cannot be connected, a warning message will be issued (not open or not connected)

#If there is no warning message, the monitor is working properly.

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

Tags: Information run check data database question monitor script test method more process help solution easy easy content boy buddy file Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi vpn Shulou Information Huawei Microsoft