Can anybody tell the correct way to use the following awk pattern check within an if statement?
When I run this command outside of the if statement
cat /tmp/test2.out | awk -v T=$TIME -v G=$GROUP -v C=$CDATE '$0 ~ T && $0 ~ G && $0 ~ C' | grep -i "Starting the group"
I get the following result which is correct
71193 07/13/2017 05:30:00 AM 0 0 0 2291124000 26204 0 seinwsprd01 nsrd NSR info Savegroup Info: Skipped starting the group 'Misc_FS_Monthly_530'.
The 3 variables are defined as
TIME=05:30
GROUP=Misc_FS_Yearly_530
CDATE=07/13/2017
But when I execute the command withing an if statement in a bash shell I get the following error.
./backup_checker.sh: line 56: 71193: command not found
Note that
71193
is the first entry in the line that matches the pattern.
This is my if statement
if `cat /tmp/test2.out | awk -v T=$TIME -v G=$GROUP -v C=$CDATE '$0 ~ T && $0 ~ G && $0 ~ C' | grep -i "Starting the group"` > /dev/null
then
:
else
echo -e "$GROUP did not start at $TIME - Please check\n" >> $OUTDIR/nonrunners.out
fi
---------- Post updated at 12:02 PM ---------- Previous update was at 11:39 AM ----------
I figured out the issue. I do not need to use ` in the if statement/condition.