On May 7, 2013, at 16:15, Reindl Harald <h.rei...@thelounge.net> wrote:

> the main question is
> 
> a) dynamically
> b) ! yesterday ! from the time the script runs
> 
> this is intended for a cron-job

Things like;

==
$ date -d yesterday
Mon May  6 16:20:20 CEST 2013

$ date -d yesterday "+%Y%m%d"
20130506
==

Add 'dateext' to your logrotate.conf, which results in logfiles with names like;

"auth.log-20130506.gz"

If you rotate daily, of course. Another option is using rsyslog, which can 
quite easily create logs in a /year/month/day/ directory structure, 
automatically generated. No need to rotate logs that way. It can also use more 
precise timestamps, like;

"2013-05-07T16:19:57.422297+02:00"

This is what we use, and it makes search yesterday's logs as easy as cd'ing 
into the right directory, and grepping to your heart's content, with something 
like this;

==
#!/bin/bash
#
#

DATESTRING="$( date -d yesterday +"%Y/%m/%d" )"
cd /var/log/${DATESTRING} || exit 1

for LOGFILE in *.log*; do
        zgrep -h 'NOQUEUE' ${LOGFILE}
done | sort
==

Adjust as required, YMMV, and so on.

HTH,
Jona

--

> Am 07.05.2013 16:09, schrieb Newton Pasqualini Filho:
>> Use AWK
>> 
>> Like this:
>> 
>> cat /var/log/maillog | awk '{ if ($1=="May" && $2=="7") print $0 }' | grep 
>> NOQUEUE
>> 
>> 
>> Em 07/05/2013, às 11:03, Reindl Harald <h.rei...@thelounge.net> escreveu:
>> 
>>> Hi
>>> 
>>> i would like a grep of all records from the previous
>>> day with "NOQUEUE" in a bash script - how do i get
>>> exactly the format like below from /var/log/maillog
>>> and yesterday?
>>> 
>>> May  7 12:29:39 mail postfix/smtpd[29696]: NOQUEUE
>>> 
>>> final goal:
>>> add the output at the bottom a my daily logwatch
> 

Reply via email to