Hi all!
While not altogether new to ksh scripting I'm certainly no expert. What I am trying to do currently is read Oracle log files and determine if any errors occured. If so, I'd like to get the log file automatically mailed to me. The script is mostly working, except for the part where I use AWK to find if the value in the "Number of rows rejected" is greater than zero. It works fine as a single command both in and out of the script, I just can't get it to work in a conditional statement or assign the value to a variable. I have searched this forum, used google, read the faqs, but still am not having any luck. Here is the script, with my variety of attempts:
Code:
#
# This script will parse an Oracle log file and if any ERROR or ORA- lines
# are found, will e-mail the log name, location, and error lines.
#
# Parms:
# $1 = log file name
logdir=$HOME/bin/load/logs/
GREP=/usr/bin/grep
AWK=/usr/bin/awk
recipients=test@test.com
rejected=$AWK '/rejected/ {print $5}' $logdir$1
#if $GREP ORA- $logdir$1; then
# cat $logdir$1 | mailx -s "Error in $1" $recipients;
#fi
#if (( $AWK \'/rejected/ {print $5}\' $logdir$1 -gt 0 )); then
# cat $logdir$1 | mailx -s "Error in $1" $recipients;
#fi
#$AWK '/rejected/ {print $5}' $logdir$1
#if [ $AWK '/rejected/ {print $5}' $logdir$1 != 0 ]; then
# cat $logdir$1 | mailx -s "Error in $1" $recipients;
#fi
if [ $rejected != 0 ]; then
cat $logdir$1 | mailx -s "Error in $1" $recipients;
fi
Any ideas would be greatly appreciated! In the meantime I'll keep working on it.