Operating System - Linux
1753893 Members
7731 Online
108809 Solutions
New Discussion юеВ

how to check the mail logs of "02-05-08" and for user "test"

 
Maaz
Valued Contributor

how to check the mail logs of "02-05-08" and for user "test"

MTA: POSTFIX

# tail -f /var/log/mail |grep "test"
Jul 3 12:16:02 tiger postfix/local[6981]: 036A23178E: to=, orig_to=, relay=local, delay=1, status=sent (delivered to mailbox)
.
.
shows all the messages related to user "test",
but I need to ADD another condition..the "date", i.e I need to grep messages of user test *but only of the specific date*
I did the following
# tail -f /var/log/mail |grep "test" |grep "Jul 2"
no results ;(

need to redirect messages related to user test on June 29 on a separate file.. following also doesn't works.
grep test /var/log/mail |grep "Jun 29" >/logs/test_mail_on_JUL29.txt
or
grep test /var/log/mail |grep "Jun 29" - >/logs/test_mail_on_JUL29.txt
help

5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: how to check the mail logs of "02-05-08" and for user "test"

Shalom,

Looks like your two step grep process will do the job.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Ivan Ferreira
Honored Contributor

Re: how to check the mail logs of "02-05-08" and for user "test"

When you need to filter a "single digit" day, you must use two spaces between the moth and the day, for example instead of "Jul 2" use "Jul 2", or a regular expresion like "Jul +2".


This command:

grep test /var/log/mail |grep "Jun 29" >/logs/test_mail_on_JUL29.txt

Should do the job. I would like to see the output of the command before the pipe.

Maybe you just don't have any mail to "test" on "Jun 29".

Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Maaz
Valued Contributor

Re: how to check the mail logs of "02-05-08" and for user "test"

Hi SEP and Ivan

following works fine
tail -f /var/log/mail |grep "test"

following doesnt works
tail -f /var/log/mail |grep "test" |grep "Jul 4"
two spaces in b/w "Jul and 4".

neither following works
tail -f /var/log/mail |grep "test" |grep "Jul +4"

but following works ;)
tail -f /var/log/mail |grep "test" |grep "Jul\ 4"
here two spaces after backslash(\), and before "4".

and following also works
# grep test /var/log/mail |grep "Jun\ 29" > mails.txt
here two spaces after backslash(\), and before "29".

i.e have to insert "" in b/w month and date. e.g "monthdate".

Regards
Dennis Handly
Acclaimed Contributor

Re: how to check the mail logs of "02-05-08" and for user "test"

>Ivan: use "Jul 2", or a regular expression like "Jul +2".

"+" is an ERE, for egrep. Use "*" for a RE.

>here two spaces after backslash(\), and before "4".

Hmm, I wouldn't think you would need a "\".
Maaz
Valued Contributor

Re: how to check the mail logs of "02-05-08" and for user "test"

Hi Dennis Handly,

>"+" is an ERE, for egrep. Use "*" for a RE.

Yes following also works

# tail -f /var/log/mail |grep "test" |grep "Jul *8"
# grep test /var/log/mail |grep "Jul *8" >
mails.txt

i.e <*> works ;)