-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathoraerr
More file actions
executable file
·220 lines (196 loc) · 8.09 KB
/
oraerr
File metadata and controls
executable file
·220 lines (196 loc) · 8.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/bin/env python
##################################################################################################
# Name: oraerr #
# Author: Randy Johnson #
# Description: Prints error information for oracle error codes. #
# #
# Usage: oraerr tns 12154 #
# oraerr TNS 12154 #
# oraerr TNS-12154 #
# oraerr tns-12154 #
# #
# #
# History: #
# #
# Date Ver. Who Change Description #
# ---------- ---- ---------------- ------------------------------------------------------------- #
# 09/19/2012 1.00 Randy Johnson Initial release. #
# 07/17/2015 2.00 Randy Johnson Updated for Python 2.4-3.4 compatibility. Added -h option. #
# #
##################################################################################################
# --------------------------------------
# ---- Import Python Modules -----------
# --------------------------------------
import codecs
from signal import signal
from signal import SIGPIPE
from signal import SIG_DFL
from optparse import OptionParser
from os import environ
from os.path import basename
from re import match
from re import search
from sys import argv
from sys import exit
# For handling termination in stdout pipe, ex: when you run: oerrdump | head
signal(SIGPIPE, SIG_DFL)
# --------------------------------------
# ---- Function Definitions ------------
# --------------------------------------
# Def : LoadFacilities()
# Desc: Parses the ficiliy file and returns a list of lists (2 dim array)
# containing:
# facility:component:rename:description
# Args: Facility file name.
# Retn: FacilitiesDD
#---------------------------------------------------------------------------
def LoadFacilities(FacilitiesFile):
FacDict = {}
FacDD = {}
try:
facfil = open(FacilitiesFile, 'r')
except:
print('Cannot open facilities file for read: %s' % FacilitiesFile)
exit(1)
FacFileContents = facfil.read().split('\n')
for line in FacFileContents:
if (not (search(r'^\s*$', line))): # skip blank lines
if (line.find('#') >= 0):
line=line[0:line.find('#')]
if (line.count(':') == 3): # ignore lines that do not contain 3 :'s
(Facility, Component, Rename, Description) = line.split(':')
FacList = [Facility.strip(), Component.strip(), Rename.strip(), Description.strip()]
if (Facility != ''):
FacDict = {
'Component' : Component.strip(),
'Rename' : Rename.strip(),
'Description' : Description.strip()
}
FacDD[Facility.strip()] = FacDict
return(FacDD)
# End LoadFacilities()
# Def : LookupMessage()
# Desc: Parses the ficiliy file and returns a list of lists (2 dim array)
# containing:
# facility:component:rename:description
# Args: Facility file name.
# Retn: FacilitiesDD
#---------------------------------------------------------------------------
def LookupMessage(MessagesFile, ErrCode):
Msg = []
HeaderFound = False
try:
###! msgfil = open(MessagesFile, 'r')
msgfil = codecs.open(MessagesFile, mode='r', encoding='ISO-8859-1', errors='strict', buffering=1)
except:
print('Cannot open Messages file for read: %s' % MessagesFile)
exit(1)
MsgFileContents = msgfil.readlines()
for line in MsgFileContents:
# lines I'm looking for look like this "00003, 00000, "INTCTL: error while se..."
# So just looking for something that starts with a string of digits and contains
# the error code I'm looking for.
if (HeaderFound):
matchObj = match(r'//,*', line)
if (matchObj):
Msg.append(line.strip())
else:
return(Msg)
else:
matchObj = match('[0]*' + ErrCode + ',', line)
if (matchObj):
ErrCode = matchObj.group()
ErrCode = ErrCode[0:ErrCode.find(',')]
Msg.append(line.strip())
HeaderFound = True
# If we get this far then we couldn't find the error code. Let's strip off leading
# 0's and try one more time. This is necessary for RMAN errors for some reason.
ErrCode = str(int(ErrCode))
for line in MsgFileContents:
if (HeaderFound):
matchObj = match(r'//,*', line)
if (matchObj):
Msg.append(line.strip())
else:
return(Msg)
else:
matchObj = match('[0]*' + ErrCode + ',', line)
if (matchObj):
ErrCode = matchObj.group()
ErrCode = ErrCode[0:ErrCode.find(',')]
Msg.append(line.strip())
HeaderFound = True
return(Msg)
# End LookupMessage()
# --------------------------------------
# ---- End Function Definitions --------
# --------------------------------------
# --------------------------------------
# ---- Begin Main Program --------------
# --------------------------------------
if (__name__ == '__main__'):
Cmd = basename(argv[0])
argc = len(argv) - 1
Usage = 'Usage: ' + Cmd + ' facility-error [-d]'
Usage += '\n ex: ' + Cmd + ' tns-12154\n'
Usage += '\nFacility is identified by the prefix string in the error message.'
Usage += '\nFor example, if you get ORA-7300, "ora" is the facility and "7300"'
Usage += '\nis the error. So you should type "' + Cmd + ' ora-7300".'
Usage += '\n'
Usage += '\nIf you get LCD-111, type "' + Cmd + ' lcd-111", and so on.'
Usage += '\n\nOther valid forms include:'
Usage += '\n ' + Cmd + ' tns 12154'
Usage += '\n ' + Cmd + ' TNS 12154'
Usage += '\n ' + Cmd + ' TNS-12154'
Usage += '\n ' + Cmd + ' tns-12154'
if ('-h' in argv):
print(Usage)
exit()
if 'ORACLE_HOME' in list(environ.keys()):
if environ['ORACLE_HOME'] == '':
print('ORACLE_HOME not set. Exiting...')
exit(1)
else:
OracleHome = environ['ORACLE_HOME']
else:
print('ORACLE_HOME not set. Exiting...')
exit(1)
if (argc >= 1 and argc <= 2):
if (argc == 1):
ErrorCode = argv[1]
try:
(Facility,ErrCode) = ErrorCode.split('-')
except:
try:
(Facility,ErrCode) = ErrorCode.split(' ')
except:
print('\nInvalid format.\n')
print(Usage)
exit(1)
elif(argc == 2):
Facility = argv[1]
ErrCode = argv[2]
else:
print('\nInvalid format.\n')
print(Usage)
exit(1)
Facility = Facility.lower()
# Get the facility information from the error msg file
FacilitiesFile = OracleHome + '/lib/facility.lis'
FacilitiesDD = LoadFacilities(FacilitiesFile)
if (not Facility in list(FacilitiesDD.keys())):
print('\nInvalid facility: %s' % Facility)
else:
MessagesFile = OracleHome + '/' + FacilitiesDD[Facility]['Component'] + '/' + 'mesg' + '/' + Facility + 'us.msg'
ErrorMessage = LookupMessage(MessagesFile, ErrCode)
print('')
if (len(ErrorMessage) > 0):
for line in (ErrorMessage):
print(line)
else:
print('Error not found : ' + ErrorCode)
print('Msg file : ' + MessagesFile)
exit(0)
# --------------------------------------
# ---- End Main Program ----------------
# --------------------------------------