Just wondering on how to get this one done.
When a job fails, is there a way to just capture the 'Fatal' log entry in the job log and send it out as an email ?
![Rolling Eyes :roll:](./images/smilies/icon_rolleyes.gif)
-Vijay
Moderators: chulett, rschirm, roy
Code: Select all
#!/usr/bin/env ksh
#Script to extract the Latest Fatal / Warning log from the job to a file.
#In addition to that, Oracle errors in ORA-nnnn format will be extracted
#Input parameters
Project=$1
Job=$2
Filename=$3
#Internal Parameter declaration
FatalEvent='Yes'
WarningEvent='Null'
#Clear the file if already exist.
echo > $Filename
#Function to fetch the timestamp in YYYMMDDHHMISS format
TimeStamp() {
Year=$9
Month=$6
if [ $Month = 'Jan' ]
then Month=01
elif [ $Month = 'Feb' ]
then Month=02
elif [ $Month = 'Mar' ]
then Month=03
elif [ $Month = 'Apr' ]
then Month=04
elif [ $Month = 'May' ]
then Month=05
elif [ $Month = 'Jun' ]
then Month=06
elif [ $Month = 'Jul' ]
then Month=07
elif [ $Month = 'Aug' ]
then Month=08
elif [ $Month = 'Sep' ]
then Month=09
elif [ $Month = 'Oct' ]
then Month=10
elif [ $Month = 'Nov' ]
then Month=11
elif [ $Month = 'Dec' ]
then Month=12
fi
Day=$7
Hour=`echo $8|cut -c'1-2'`
Minute=`echo $8|cut -c'4-5'`
Second=`echo $8|cut -c'7-8'`
JobTime=${Year}${Month}${Day}${Hour}${Minute}${Second}
echo $JobTime
}
cd `cat /.dshome`
#Job Start Time stamp for the current run
JobStartTime=`dsjob -jobinfo $Project $Job | grep 'Job Start Time'`
JobStartTime=`TimeStamp $JobStartTime`
echo JobStartTime : $JobStartTime
#Job End Time stamp for current run
JobEndTime=`dsjob -jobinfo $Project $Job | grep 'Last Run Time'`
JobEndTime=`TimeStamp $JobEndTime`
echo JobEndTime : $JobEndTime
#Latest available Fatal even id for the given job
FatalEventId=`dsjob -lognewest $Project $Job FATAL | awk '{print $4}'`
echo Fatal Evenid $FatalEventId
if (( $FatalEventId != 0 )) #If there is no fatal error at all...
then
#Timestamp of Fatal error event
`dsjob -logdetail $Project $Job $FatalEventId > ${Filename}_temp`
FatalTime="Dummy1 Dummy2 "`cat ${Filename}_temp | grep "Time"` #Padded with required number of parameters
FatalTime=`TimeStamp $FatalTime`
#Check for the event wehter its belongs to current run
if (( $FatalTime >= $JobStartTime ))
then
MainEventId=$FatalEventId
else
FatalEvent='No'
fi
else
FatalEvent='No'
fi
#If there is not Fatal erro for the current run...
if ([ $FatalEvent = 'No' ])
then
#Latest available Warning event id
WarningEventId=`dsjob -lognewest $Project $Job WARNING | awk '{print $4}'`
if (( $WarningEventId != 0 ))
then
#Check for the event wehter its belongs to current run
`dsjob -logdetail $Project $Job $WarningEventId > ${Filename}_temp`
LogDetail=`cat ${Filename}_temp | grep "Time"`
WarningTime="Dummy1 Dumm2 "$LogDetail
WarningTime=`TimeStamp $WarningTime`
if (( $WarningTime >= $JobStartTime ))
then
MainEventId=$WarningEventId
else
echo Warning is not for current run.
WarningEvent='No'
fi
else
WarningEvent='No'
fi
fi
if ([ $FatalEvent = 'No' ] && [ $WarningEvent = 'No' ])
then
echo There is neither Fatal error nor Warning for this current run.
else
#To explore 2 events up and down in addition to the current FATAL or WARNING event to get more detail
EndLoop=`expr $MainEventId + 2`
EndJobCheck=`dsjob -lognewest $Project $Job | awk '{print $4}'`
#If the FATAL or WARNING event is last but one
if (( $EndJobCheck < $EndLoop ))
then
EndLoop=$EndJobCheck
fi
i=`expr $MainEventId - 2`
while (( $i <= $EndLoop )); do
`dsjob -logdetail $Project $Job $i > ${Filename}_temp`
Type=`cat ${Filename}_temp | grep "Type" | awk '{print $3}'`
if ([ $Type = 'FATAL' ] || [ $Type = 'WARNING' ])
then
`cat ${Filename}_temp >> $Filename`
#echo `echo $LogDetail >> ${Job}${JobStartTime}-${JobEndTime}\n`
echo Oracle Error If Any...`echo $LogDetail | sed 's/\(.*\)\(ORA-[0-9]\{5,5\}:\)\(.*\)/\2\3/'`
fi
i=`expr $i + 1`
#Removing temp file created
rm ${Filename}_temp
done
fi
The "$4" used with awk just prints the fourth column from the output, in this case will print only the fatal or warning ID, so you don't have to give that as input. This script (kumar's post) is a shell script and needs to be invoked from the sequence in the event of a failure and hence has to be incorporated in your job sequence.Roopanwita wrote:Hi,
I got a query for the post...
which parameter is $4?
Can I use DSRUNJOB script of Ascential to run the sequence?
Roopanwita wrote:By using built in stage ,I am able to send only job status( finished/finished with warning/aborted) only..
Well, do this: in your job sequence, take a notification activity from the palette and open it's properties (the place where you have to mention the to and from addresses as well as the subject and body) and look for the check box of "Include job status in email" and switch it on and then see what happens.Roopanwita wrote:Thanks for reply.
Than I am not aware of it.Can you please guide me ...
Thanks ...