Newbie here with first post. I've got a shell script (ksh) whereby I run a SQL*Plus script and output the results to a file. I then check the output file in an if statement that looks like this:
if [[ -e $OUTFILE ]]; then
export GAPNUM=`awk '{print $4}' $OUTFILE`
if [[ $GAPNUM -ge 5 ]] then
mailx -s "Possible Redo Apply Issue at $ORACLE_SID - Log Gap is "$GAPNUM" $MAIL_TO < $OUTFILE
mv $OUTFILE $OUTFILE.$DAYHOUR
fi
else
echo "$OUTFILE does not exist" | mailx -s $SUBJECT $MAIL_TO
fi
Everything works fine except when the email is sent, although $ORACLE_SID value displays, $GAPNUM does not. I've searched on this site and others and am not sure what I'm doing wrong. If I place an echo $GAPNUM just before the mailx line it displays. What am I missing?
Thanks, but that is a single line and works fine. My issue is that the variable $GAPNUM does not show in the subject line, even though the other variable in the subject line ($ORACLE_SID) does.
Yup, did that and it echoes the correct value of 0, which stumped me even more. I totally don't understand why it displays in the previous line (i.e the echo) but not in the subject line.
There are at least two problems here that don't match with your description. If $GAPNUM expands to 0 as you say it does, the mailx won't be executed because zero is not greater than or equal to 5. This statement is also missing a semicolon before the then .
My apologies, I'm trying to do too much at once. For testing purposes, I changed my code to -le 5 so I could get the email. The current code is as-follows:
if [[ -e $OUTFILE ]]; then
export GAPNUM=`awk '{print $4}' $OUTFILE`
if [[ $GAPNUM -le 5 ]] then
mailx -s "Possible Redo Apply Issue at $ORACLE_SID - Log Gap is $GAPNUM" $MAIL_TO < $OUTFILE
mv $OUTFILE $OUTFILE.$DAYHOUR
fi
else
echo "$OUTFILE does not exist" | mailx -s $SUBJECT $MAIL_TO
fi
If I execute this as-is, following is the email I receive:
-----Original Message-----
From: Oracle <oracle@xxxxxxxxx>
Sent: Friday, August 2, 2019 11:11 AM
To: Laura
Subject: Possible Redo Apply Issue at omsprd - Log Gap is
0
3 23200 23200 0
So it appears to put the $GAPNUM in the body of the email instead of the Subject line.