bash - awk grep the last 30 days of logs by keyword -


trying precise query of log files (i.e. bounces in last 30 days).

i seam missing 2 factors, don't think stdin pull zcat info , think there error passing variable awk.

home # lastdate=$(date -d "last month" 2>&1 {$1, $2, $3}) | cat /var/log/messages | zcat /var/log/messages-* | awk '$0>=from&&$0<=to' from='{ print date +"%m-%d"}' to=$lastdate '{print to}' | grep -i reject awk: fatal: cannot open file `{print to}' reading (no such file or directory) 

where broke:

lastdate=$(date -d "last month" 2>&1 {$1, $2, $3})|awk '{print lastdate}'    no error, no output 

date -d "last month" fri jul 26 07:13:40 utc 2013

do not use tics, use parentheses:

awk 'tolower($0)~/reject/ && $0~date' date=$(date -d'now-30 days' +[%d/%b:%h:%m:%s) /var/log/messages && zcat /var/log/messages-* 

in post, not use date, records regardless date is

ps update post #1, instead of posting new.

edit: if range of date, not use on day, 30 day ago, try this:

awk 'tolower($0)~/reject/ && $0>=from && $0<=to' from=$(date -d'now-30 days' +[%d/%b:%h:%m:%s) to==$(date +[%d/%b:%h:%m:%s) /var/log/messages && zcat /var/log/messages-* 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -