check datagurad scripts using python

#!/usr/bin/python
# -*- coding: utf-8 -*-
import cx_Oracle
import string
from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
import smtplib
import sys
import getopt
import re

opts, args = getopt.getopt(sys.argv[1:], ‘H:‘)

p = re.compile(r"^((?:(2[0-4]\d)|(25[0-5])|([01]?\d\d?))\.){3}(?:(2[0-4]\d)|(255[0-5])|([01]?\d\d?))$")
ip = opts[0][1]
flag = p.match(ip)
if not flag:
    sys.exit()

mail_host = ‘smtp.qq.com‘
mail_user = ‘[email protected]‘
mail_pwd = ‘12312312‘
to_list = [ ‘[email protected]‘, ‘[email protected]‘ ]

conn = cx_Oracle.connect(‘read/[email protected]%s/test‘ % ip)
cursor = conn.cursor ()  

cursor.execute (‘‘‘ select max(sequence#) from v$archived_log where dest_id=1 and thread#=%s ‘‘‘ % ‘1‘)
#rows = cursor.fetchall()
rows = cursor.fetchone()
thread1Primary = rows[0]
cursor.execute (‘‘‘ select max(sequence#) from  v$log_history  where thread#=%s ‘‘‘ % ‘1‘)
rows = cursor.fetchone()
thread1Standby = rows[0]

cursor.execute (‘‘‘ select max(sequence#) from v$archived_log where dest_id=1 and thread#=%s ‘‘‘ % ‘2‘)
rows = cursor.fetchone()
thread2Primary = rows[0]
cursor.execute (‘‘‘ select max(sequence#) from  v$log_history  where thread#=%s ‘‘‘ % ‘2‘)
rows = cursor.fetchone()
thread2Standby = rows[0]

#    print (",").join(map(lambda x: str(x),row))
cursor.close ()
conn.close ()  

diffThread1 = thread1Primary - thread1Standby
diffThread2 = thread2Primary - thread2Standby

#msg = u‘‘‘
#            DATAGUARD SYNC ERROR
#              thread1Primary = %s
#              thread1Standby = %s
#              thread2Primary = %s
#              thread2Standby = %s
#‘‘‘ % (str(thread1Primary),str(thread1Standby),str(thread2Primary),str(thread2Standby))
#
#
#print msg
if diffThread1 != 0 or diffThread2 !=0:
    msg = u‘ DATAGUARD ERROR : thread1Primary = %s thread1Standby = %s thread2Primary = %s thread2Standby = %s ‘ % (str(thread1Primary),str(thread1Standby),str(thread2Primary),str(thread2Standby))
    sys.exit(2)
else:
    msg = u‘ DATAGUARD OK : thread1Primary = %s thread1Standby = %s thread2Primary = %s thread2Standby = %s ‘ % (str(thread1Primary),str(thread1Standby),str(thread2Primary),str(thread2Standby))
    print msg

#    send_email( msg, to_list, ‘DATAGUARD SYNC ERROR‘)
时间: 2024-11-02 15:30:57

check datagurad scripts using python的相关文章

Check iO:初学Python

The end of other For language training our Robots want to learn about suffixes. In this task, you are given a set of words in lower case. Check whether there is a pair of words, such that one word is the end of another (a suffix of another). For exam

[转]Installing python 2.7 on centos 6.3. Follow this sequence exactly for centos machine only

Okay for centos 6.4 also On apu.0xdata.loc, after this install was done $ which python /usr/local/bin/python $ python -V Python 2.7.3 $ ls -ltr /usr/local/bin/pyth* lrwxrwxrwx 1 root root 24 Jan 30 2013 /usr/local/bin/python -> /usr/local/bin/python2

Seven Python Tools All Data Scientists Should Know How to Use

Seven Python Tools All Data Scientists Should Know How to Use If you’re an aspiring data scientist, you’re inquisitive – always exploring, learning, and asking questions. Online tutorials and videos can help you prepare you for your first role, but t

Python Tutorial 学习(二)--Using the Python Interpreter

Using the Python Interpreter 2.1. Invoking the Interpreter The Python interpreter is usually installed as /usr/local/bin/python on those machines where it is available; putting /usr/local/bin in your Unix shell’s search path makes it possible to star

002 使用 Python 解释器

2. 使用 Python 解释器 2.1. Python 解释器的调用 Python 解释器通常被安装在机器的 /usr/local/bin/python3.6 目录下,如果该目录是可用的话:用你的 Unix shell 搜索 /usr/local/bin 目录然后键入如下命令开始:[1] python3.6 Since the choice of the directory where the interpreter lives is an installation option, other

python 工具链 虚拟环境和包管理工具 pipenv

Pipenv is a tool that aims to bring the best of all packaging worlds (bundler, composer, npm, cargo, yarn, etc.) to the Python world. Windows is a first-class citizen, in our world. pipenv 是Kenneth Reitz大神的作品,能够有效管理Python多个环境,各种包.过去我们一般用virtualenv搭建虚

Python语言学习 (一)1.2

1. 打开PyCharm,Create Project,选择Pure Python,Location为存放代码的地址,Interpreter为使用的解释器,选择安装过的anaconda的解释器. 2. New Directory,再在文件夹上New Python File.可以开始写代码了:print 'hello world'   点击run按钮就可以执行出结果了:hello world. 在default settings里Editor ->File and Code Templates -

Comprehensive learning path – Data Science in Python

http://blog.csdn.net/pipisorry/article/details/44245575 关于怎么学习python,并将python用于数据科学.数据分析.机器学习中的一篇很好的文章 Comprehensive(综合的) learning path – Data Science in Python Journey from a Pythonnoob(新手) to a Kaggler on Python So, you want to become a data scient

开发环境python

python开发环境搭建 虽然网上有很多python开发环境搭建的文章,不过重复造轮子还是要的,记录一下过程,方便自己以后配置,也方便正在学习中的同事配置他们的环境. 1.准备好安装包 1)上python官网下载python运行环境(https://www.python.org/downloads/),目前比较稳定的是python-3.5.2 2)上pycharm官网下载最新版的IDE(http://www.jetbrains.com/pycharm/download/#section=wind