Ok, So up front I'm going to say that I'm a very elementary scripter, and I tend to use tools I don't fully understand, but I shotgun at something until I can get it to work...that said, I can't for the life of me understand why I can't get this to go down the way I want it to.
The goal:
-to establish todays date
-to take a look at a log file (in this case the /var/adm/messages log)
-to check if the last line of the log matches todays date and if so ... (eventually it will be to dump all lines of the log with todays date to a text file that will at some point be picked up by the notification server and go out in an email)
My issue is that though I can establish the date, and create variables based upon it, I can't get nawk to accept the variables I've created.
What I have so far:
#!/usr/bin/bash
#collect todays date (date)
d=`date|awk '{print $3}'`
#collect todays date (month)
m=`date|awk '{print $2}'`
#collect errors for todays date (day and month)
e=`grep ""$d" "$m"" /var/adm/messages`
tail -1 /var/adm/messages|nawk -v m=$m -v d=$d '{if ($1 == "$m" && $2 == "$d") print "success"}'
#if
# [ "$z" = "success" ];
#then echo "$e"
#fi
this returns nothing, no errors, just goes straight back to the prompt.
Now as a matter of checking my work I've tried replacing that last nawk statement with
tail -1 /var/adm/messages|nawk -v m=$m '{print $m}'
I figured this would at least tell me if my variable is making it into the nawk statement, but this returns:
"nawk: illegal field $(Mar)
input record number 1
source line number 1"
the last thing that I've tried, just to make sure my syntax isn't completely foobar was
tail -1 /var/adm/messages|nawk -v m=$m -v d=$d '{if ($1 == "Mar" && $2 == "30") print "success"}'
and that returns success...
So from what I can gather, my overall nawk statement is good, it's just not using the variables from the rest of the script.
So any input would be appreciated. Also (although, I want to learn this way) if anyone has any insight on a better method of keeping track of the messages log (or any log) please chime in.