1834970 Members
2011 Online
110072 Solutions
New Discussion

Re: Script error

 
tayal_sumit
Occasional Advisor

Script error

Hi All,

I have created that script and when i executed this script i have soome error below i am mentioning the script as well as error.

SR1> vi chkalert.sh
"chkalert.sh" 66 lines, 1143 characters
clear
# Script checks for ORA error in alert log file
# Error occured Post midnight
# Date : May 29 2008

DT=`date '+%b %d'`
export DT

#
# Mention Alert file location
#

ALR_LOG=/ora9/home/dba/oracle/admin/mul/bdump
export ALR_LOG

# echo $DT $ALR_LOG

#
# Count Total number of lines in log file
#

A=`wc -l $ALR_LOG|awk '{print \$1}'`

# echo $A

#
# Find Line number when Today's first entry started in log file
#

B=`grep -n "$DT" $ALR_LOG|head -1|awk -F: '{print \$1}'`

#
# Store total lines to be displayed from tail of log file by doing minus on A and B value
#

TAIL=`echo $A $B - p |dc`

# echo $TAIL

#
# Display the ORA Error
#
echo
echo "################ Total ORA error Occurance Between Midnight and Now ############"
echo
tail -f $TAIL $ALR_LOG|awk '/^ORA/{print}'

#
echo

echo "###### Display all distinct errrors ###########"
#

tail -f $TAIL $ALR_LOG|awk '/^ORA/{print}' |sort|uniq

#
# Alert when error is not from below List
#

echo
echo "######## Alert when error is not from below List #############"
echo
echo " ORA -00060 "
echo " ORA-02396 "
echo
echo " ###################### - - - ##################### "
"chkalert.sh" 66 lines, 1141 characters
SR1>
SR1>
SR1>




SR1> ./chkalert.sh

################ Total ORA error Occurance Between Midnight and Now ############

tail: Can only process one file at a time.
Usage: tail [-f] [-c number|-n number|-m number|-b number|-k number] [file]
Usage: tail [-r] [-n number] [file]
Usage: tail [+|-[number]][l|b|c|k|m][f] [file]

###### Display all distinct errrors ###########
tail: Can only process one file at a time.
Usage: tail [-f] [-c number|-n number|-m number|-b number|-k number] [file]
Usage: tail [-r] [-n number] [file]
Usage: tail [+|-[number]][l|b|c|k|m][f] [file]

######## Alert when error is not from below List #############

ORA -00060
ORA-02396

###################### - - - #####################


Please reply as soon as possible
regards,
2 REPLIES 2
Dennis Handly
Acclaimed Contributor

Re: Script error

>tail: Can only process one file at a time.

To debug script errors you ask the commands to be echoed. "set -x"

In particular you should echo $TAIL.

General comments on your script:
1) You should start with: #!/usr/bin/sh
2) export DT
No need to export local variables.

3) Replace: A=`wc -l $ALR_LOG|awk '{print \$1}'`
A=$(wc -l < $ALR_LOG)
Note: You don't need a "\" before the "$" if inside ''.

4) B=`grep -n "$DT" $ALR_LOG | head -1| awk -F: '{print \$1}'`
No need for that "\":
B=$(grep -n "$DT" $ALR_LOG | head -1| awk -F: '{print $1}')
You could do it all in awk:
B=$(awk -v DT="$DT" '$0 ~ DT { print NR; exit }'

5) TAIL=`echo $A $B - p |dc`
No need for dc if your files are small. And on 11.23, you don't need to worry:
TAIL=$(( A - B ))

6) tail -f $TAIL $ALR_LOG|awk '/^ORA/{print}' |sort|uniq
grep will work fine here:
tail -f $TAIL $ALR_LOG | grep "^ORA" | sort -u
Dennis Handly
Acclaimed Contributor

Re: Script error

B=$(awk -v DT="$DT" '$0 ~ DT { print NR; exit }'

Oops, forgot the file:
B=$(awk -v DT="$DT" '$0 ~ DT { print NR; exit }' $ALR_LOG