Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import cx_Oracle
- import ConfigParser
- import re
- import time
- from datetime import datetime
- # To fix trouble with codepage
- import os
- os.environ["NLS_LANG"] = "Russian.AL32UTF8"
- i = 0
- # Read file with credential
- def read_oracle_cred(db_instance):
- if os.path.exists('./connect.ini'):
- send_to_log(' > Config file exists. Begin reading ini file')
- time.sleep(1)
- parser = ConfigParser.ConfigParser()
- parser.read('./connect.ini')
- db_host = parser.get(db_instance, 'db_host')
- db_port = parser.get(db_instance, 'db_port')
- db_sid = parser.get(db_instance, 'db_sid')
- db_user = parser.get(db_instance, 'db_user')
- db_pass = parser.get(db_instance, 'db_pass')
- else:
- send_to_log(' > Config file not exists. Can`t continue work')
- send_to_log(' > End work')
- raise SystemExit(1)
- oracle_array = (db_host,db_port,db_sid,db_user,db_pass)
- send_to_log(' > Config file read success')
- return oracle_array
- # Work with message
- def send_to_log(msg):
- cur_time = str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
- print (cur_time+msg)
- f.write(cur_time+msg+'\n')
- # Check connection to database
- def check_connection(db_instance):
- send_to_log(' > Selected SID: '+db_instance.upper())
- sql = 'select 1 from dual'
- c.execute(sql)
- for row in c:
- res = str(row[0])
- if res == '1':
- send_to_log(' > Connection established')
- time.sleep(1)
- else:
- send_to_log(' > Connection lost. Breake script')
- time.sleep(1)
- raise SystemExit(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement