If statement in awk with external variable

So I have a if statement inside an awk to check if $2 of a awk equals a specific IP but the test fails. So here is what I have.

# !/bin/sh
echo "Enter client ID"
read ID

echo "Enter month (01, 02, 03)"
read month

echo "Enter day (03, 15)"
read day

echo "Enter Year (07, 08)"
read year

date=$year$month$day

echo "Enter the source IP (x.x.x.x)"
read source

if (ls /archive/$ID$date.gz | awk '{print $1}'); then

    echo "Please wait while your request is being processed."

zcat /archive/$ID$date.gz | awk '{FS = "^"} {if($2==$source) {print $1}}' | awk '{print $7}' | sort | uniq -c | sort -n

else
echo "Couldn't find file"
exit
fi;;

What you see when its run

Enter client ID
1234
Enter month (01, 02, 03)
12
Enter day (03, 15)
10
Enter Year (07, 08)
08
Enter the source IP (x.x.x.x)
10.1.5.42
archive/1234081210.gz
Please wait while your request is being processed.

#

No results but there should be...

However if I run the following manually it works fine

zcat /archive/1234081210.gz | awk '{FS = "^"} {if($2=="10.1.5.42") {print $1}}' | awk '{print $7}' | sort | uniq -c | sort -n
2 122:3:0
5 122:7:0
27 3:13416:1

So the problem seems to do with getting the if($2==$source) part working. I'm not sure if this is where the awk -v would come into play but any help would be appreciated.

TIA

search the awk man page look for awk -v option
that will solve your problem

awk -v src=$source '$2==src

and so on with the rest of your commands
Note that I renamed what the script treated as $source to src; to be shorter in awk and to demonstrate that the same names are not required.

Why would doing it like this provide no results?

zcat /archive/$ID$date.gz | awk -v src=$source '{FS = "^"} {if($2==$src) {print $1}}' | awk '{print $7}' | sort | uniq -c | s$

Not

{if($2==$src) {print $1}}' 

but

{if($2==src) {print $1}}' 

Use the $ in scripts, but not inside awk

whoops cut some of it off in the previous post.

zcat /archive/$ID$date.gz | awk -v src=$source '{FS = "^"} {if($2==$src) {print $1}}' | awk '{print $7}' | sort | uniq -c | sort -n

oh yea, forgot to remove it from the $source. That fixed it, thanks man!