Hello everyone, I am looking to do the exact same thing as the original poster. I have a few questions about Kumar_s's script.
Q1: Line 1,2,3: Your script expects input parameters of Project, Job and Filename. If I have a job sequence with 10 jobs and the 5th one failed, how do I know what "Job" is?
Q2: Line 81: What is $4, the 4th parameter?
Q3: Line 15,16,42: You are expecting the year, month, timestamp and day values to be passed. Shouldn't you be just taking the current system values?
Q4: If I want to call this when a sequence job aborts, where would I put this code?
I would appreciate it if anybody could answer these questions. Thanks.
-------------------------------------------------------------------------------------
1)#!/usr/bin/env ksh
2)#Script to extract the Latest Fatal / Warning log from the job to a file.
3)#In addition to that, Oracle errors in ORA-nnnn format will be extracted
4)#Input parameters
5)Project=$1
6)Job=$2
7)Filename=$3
![Cool 8)](./images/smilies/icon_cool.gif)
#Internal Parameter declaration
9)FatalEvent='Yes'
10)WarningEvent='Null'
11)#Clear the file if already exist.
12)echo > $Filename
13)#Function to fetch the timestamp in YYYMMDDHHMISS format
14)TimeStamp() {
15)Year=$9
16)Month=$6
17)if [ $Month = 'Jan' ]
18) then Month=01
19)elif [ $Month = 'Feb' ]
20) then Month=02
21)elif [ $Month = 'Mar' ]
22) then Month=03
23)elif [ $Month = 'Apr' ]
24) then Month=04
25)elif [ $Month = 'May' ]
26) then Month=05
27)elif [ $Month = 'Jun' ]
28) then Month=06
29)elif [ $Month = 'Jul' ]
30) then Month=07
31)elif [ $Month = 'Aug' ]
32) then Month=08
33)elif [ $Month = 'Sep' ]
34) then Month=09
35)elif [ $Month = 'Oct' ]
36) then Month=10
37)elif [ $Month = 'Nov' ]
38) then Month=11
39)elif [ $Month = 'Dec' ]
40) then Month=12
41)fi
42)Day=$7
43)Hour=`echo $8|cut -c'1-2'`
44)Minute=`echo $8|cut -c'4-5'`
45)Second=`echo $8|cut -c'7-8'`
46)JobTime=${Year}${Month}${Day}${Hour}${Minute}${Second}
47)echo $JobTime
48)}
49)cd `cat /.dshome`
50)#Job Start Time stamp for the current run
51)JobStartTime=`dsjob -jobinfo $Project $Job | grep 'Job Start Time'`
52)JobStartTime=`TimeStamp $JobStartTime`
53)echo JobStartTime : $JobStartTime
54)#Job End Time stamp for current run
55)JobEndTime=`dsjob -jobinfo $Project $Job | grep 'Last Run Time'`
56)JobEndTime=`TimeStamp $JobEndTime`
57)echo JobEndTime : $JobEndTime
58)#Latest available Fatal even id for the given job
59)FatalEventId=`dsjob -lognewest $Project $Job FATAL | awk '{print $4}'`
60)echo Fatal Evenid $FatalEventId
61)if (( $FatalEventId != 0 )) #If there is no fatal error at all...
62)then
63) #Timestamp of Fatal error event
64) `dsjob -logdetail $Project $Job $FatalEventId > ${Filename}_temp`
65) FatalTime="Dummy1 Dummy2 "`cat ${Filename}_temp | grep "Time"` #Padded with required number of parameters
FatalTime=`TimeStamp $FatalTime`
66) #Check for the event whether it belongs to current run
67) if (( $FatalTime >= $JobStartTime ))
68) then
69) MainEventId=$FatalEventId
70) else
71) FatalEvent='No'
72) fi
73)else
74) FatalEvent='No'
75)fi
76)#If there is no Fatal error in the current run...
77)if ([ $FatalEvent = 'No' ])
78)then
79) #Latest available Warning event id
80) WarningEventId=`dsjob -lognewest $Project $Job WARNING |
81)awk '{print $4}'`
82) if (( $WarningEventId != 0 ))
83) then
84) #Check for the event wehter its belongs to current run
85) `dsjob -logdetail $Project $Job $WarningEventId > ${Filename}_temp`
86) LogDetail=`cat ${Filename}_temp | grep "Time"`
87) WarningTime="Dummy1 Dumm2 "$LogDetail
88) WarningTime=`TimeStamp $WarningTime`
89) if (( $WarningTime >= $JobStartTime ))
90) then
91) MainEventId=$WarningEventId
92) else
93) echo Warning is not for current run.
94) WarningEvent='No'
95) fi
96) else
97) WarningEvent='No'
98) fi
99)fi
100)if ([ $FatalEvent = 'No' ] && [ $WarningEvent = 'No' ])
101)then
102) echo There is neither Fatal error nor Warning for this current run.
103)else
104) #To explore 2 events up and down in addition to the current FATAL or WARNING event to get more detail
105) EndLoop=`expr $MainEventId + 2`
106) EndJobCheck=`dsjob -lognewest $Project $Job | awk '{print $4}'`
107) #If the FATAL or WARNING event is last but one
108) if (( $EndJobCheck < $EndLoop ))
109) then
110) EndLoop=$EndJobCheck
111) fi
112) i=`expr $MainEventId - 2`
113) while (( $i <= $EndLoop )); do
114) `dsjob -logdetail $Project $Job $i > ${Filename}_temp`
115) Type=`cat ${Filename}_temp | grep "Type" | awk '{print $3}'`
116) if ([ $Type = 'FATAL' ] || [ $Type = 'WARNING' ])
117) then
118) `cat ${Filename}_temp >> $Filename`
119) #echo `echo $LogDetail >> ${Job}${JobStartTime}-${JobEndTime}\n`
120) echo Oracle Error If Any...`echo $LogDetail | sed 's/\(.*\)\(ORA-[0-9]\{5,5\}:\)\(.*\)/\2\3/'`
fi
121) i=`expr $i + 1`
122) #Removing temp file created
123) rm ${Filename}_temp
124) done
125)fi
-------------------------------------------------------------------------------------