博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PYTHON测试脚本
阅读量:2432 次
发布时间:2019-05-10

本文共 2514 字,大约阅读时间需要 8 分钟。

#!/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博客 ” ,链接:http://blog.itpub.net/28371090/viewspace-2151831/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/28371090/viewspace-2151831/

你可能感兴趣的文章
小白也能看懂的 Java 异常处理
查看>>
C++ 是如何从代码到游戏的?
查看>>
厉害!国内大学生计算机编程第一人,一人挑战一个队,百度最年轻 T10,现创业自动驾驶...
查看>>
三分钟黑了阿里?马云下死命令留他?吴翰清辟谣:我没黑过阿里
查看>>
如果重新一次高考,你还会选择软件专业当程序员吗? | 每日趣闻
查看>>
如何设计一个安全可靠的 API 接口?
查看>>
大厂技术文档:Redis+Nginx+Spring全家桶+Dubbo精选
查看>>
笑死,别再黑程序员了好吗? | 每日趣闻
查看>>
Python 爬取 13966 条运维招聘信息,这些岗位最吃香
查看>>
以太坊创始人V 神:普通人看见现在,天才看见未来
查看>>
一周内咸鱼疯转 2.4W 次,最终被所有大厂封杀!
查看>>
关于鸿蒙 2.0,那些开发者不知道的一切
查看>>
Google 排名第一的语言,引数十万人关注:搞定它,技术大牛都甘拜下风
查看>>
软件开发行业,年轻与大龄程序员的生存现状
查看>>
打开数“智”化之门,一字之差带来的思考
查看>>
漫画 | TCP,一个悲伤的故事
查看>>
张一鸣无圈胜破圈?
查看>>
干货! AI 推断解决方案栈 Vitis AI 全流程独家解析
查看>>
真相了 | 敲代码时,程序员戴耳机究竟在听什么?
查看>>
回首互联网十年,我们能从八次烧钱大战中学到什么
查看>>