I'm trying to list the last users logged in before 2pm to a machine. I set two bash variables to use with the last command piped to awk.
month=$(date | awk '{printf"%s\n",$2}')
yesterday=$(date | awk '{printf"%s\n",$3-1}')
I then try to use these two variables, but it doesn't work when I do it like this.
last | awk -v month="$month"'{
if($5==month && $6=="19" && $7 < "14:00"){
printf "%s\n",$0
}
}'
last | awk -v month="$month" -v yesteday="$yesterday" '{
if($5==month && $6==yesterday && $7 < "14:00"){
printf "%s\n",$0
}
}'
Both of these attempts did not work. However, if I set the variables to a string like "Apr" it does work. Like so:
last | awk -v month="Apr" '{
if($5==month && $6=="19" && $7 < "14:00"){
printf "%s\n",$0
}
}'
Here is output of it working with the above command.
My question is, how can I get it to work with my bash variables? I looked at similar questions but those didn't help me. My bash variables work if I just set them then print them using awk, but it isn't working when I use them in my if statement.
Thank you.

$5? Also, what operating system are you using? (I.e. which version ofdate-- GNU, BSD, something else?) Also, please consider copying and pasting formatted text into your question rather than images. If we want to replicate your results, we shouldn't have to re-type your code and input data.