ITPub博客

首页 > 应用开发 > IT综合 > PYTHON测试脚本

PYTHON测试脚本

原创 IT综合 作者:germany006 时间:2018-03-14 10:15:09 0 删除 编辑


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


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28371090/viewspace-2151831/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
ORACLE,MYSQL,POSTGRESQL,SQLSERVER,MONGODB,TIDB,DB2,REDIS,本博客只为记录自己学习总结,不代表完全准确。

注册时间:2013-03-06

  • 博文量
    776
  • 访问量
    1038357