LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   oracle alert log script (https://www.linuxquestions.org/questions/programming-9/oracle-alert-log-script-684917/)

Lachhman 12-28-2014 05:57 AM

have a look at script i want to add multiple error in "ALERT" Variable but getting error nor getting required result.when im writing only one error then script is running successfully.Kindly suggest me how i add multiple error in this script as i can get required result.
For single hard code error like ALERT="ORA-00060" it working perfect.

Thanks in advance.



#!/bin/sh

#GLOBS
ALERT="ORA-00060","TNS","crash","Error",'abort","cannot allocate","not complete","waiting","All online" ;
LOGFILE=/path/to/my/alert_X.log
MYFILE=/home/user/test.log
##


#get the errors out of the logfile.
grep -h "$ALERT" $LOGFILE >> $MYFILE

#count number of lines in myfile, and print.
VAR=`wc -l $MYFILE | awk -F" " '{print $1}'`
#echo $VAR



# if the amount of lines is greater than 0, then cat the file and send it to me. if not then echo all clear.

#size variable is the number of errors the last time the script ran

size=`wc -l test.last | awk -F" " '{print $1}'`
echo $size

# if the amount of lines is greater than 0, then cat the file and send it to me. if not then echo all clear

if [[ $VAR -gt $size ]] ; then

cat $MYFILE | mail -vs "oralert" user@domain.com ;

else
echo "All clear.."


fi;

rm test.last
mv test.log test.last

Lachhman 12-28-2014 05:59 AM

Please suggest me how to add diff critical error in this script.
here in this script u have only defined one ALERT="ORA-00060"; .I tried to add multiple error as same type of error came in my alert log so i can easily rectify ASAP.Kindly help me add multiple ora error nhn with ALERT="ORA-00060";
Thanks in Advance

unSpawn 12-28-2014 06:27 AM

While English may not be your first language you must realize that just repeating your question isn't going to solve things.

It should look something like this:
Code:

#!/bin/sh --
# Unset debug mode when done testing:
set -Cvxe
# Set default behaviour:
LANG=C; LC_ALL=C; export LANG LC_ALL
# The alert codes to look for:
ALERTS="ORA-00060|ORA-00061|ORA-00062";
# The log file and location:
LOGFILE=/path/to/my/alert_X.log
# The email address to report to:
EMAILADDR="email@domain.com"

# Use a temporary directory to hold temporary files:
export TMPDIR=/tmp; _MYTMPDIR=`mktemp -p "${TMPDIR}" -d ${oralert}.XXXXXXXXXX` && {
 # Get the errors out of the logfile:
 egrep -h "($ALERT)" "${LOGFILE}" > "${_MYTMPDIR}/tempfile" 2>/dev/null;
 # Count number of lines:
 LINECOUNT=$(wc -l "${_MYTMPDIR}/tempfile" 2>/dev/null|awk -F" " '{print $1}')
 # If the amount of lines is greater than 0, then cat the file and send it.
 # If not then clean up and exit cleanly.
 [ ${LINECOUNT} -gt 0 ] && { cat "${_MYTMPDIR}/tempfile"|mail -vs "oralert" "${EMAILADDR}"; }
 } # End Mktemp
rm -rf "${_MYTMPDIR}" || exit 127
exit 0



All times are GMT -5. The time now is 12:20 AM.