Generate script perl mail log not work


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Generate script perl mail log not work
# 1  
Old 05-30-2011
Generate script perl mail log not work

Dear unix forum members,
I'm working on a script that will parse a mail machine's logs and print a list of email addresses in this format:
authen@domain.com | sender@domain | recipient@domain
exam
account1@domain1.com | sender2@domain2.com | brian5841@yahoo.com,brooke_leee@yaho...0809@yahoo.com
or
account1@domain1.com | sender2@domain2.com | brian5841@yahoo.com
account1@domain1.com | sender2@domain2.com | brooke_leee@yahoo.com
account1@domain1.com | sender2@domain2.com | c0809@yahoo.com
The logs look something like this:
Feb 18 20:00:11 mail postfix/smtpd[27053]: F33E01715C9: client=unknown[22.22.22.22], sasl_method=LOGIN, sasl_username=account1@domain1.com
Feb 18 20:00:14 mail postfix/cleanup[27072]: F33E01715C9: message-id=<JGWU@domain2.com>
Feb 18 20:00:14 mail postfix/qmgr[27047]: F33E01715C9: from=<sender2@domain2.com>, size=5578, nrcpt=30 (queue active)
Feb 18 20:00:20 mail postfix/smtp[27117]: F33E01715C9: to=<brian5841@yahoo.com>, relay=127.0.0.1[127.0.0.1]:10024, delay=8.5, delays=2.6/0.01/0.01/5.9, dsn=2.0.0, status=sent (250 2.0.0 Ok, id=13740-01, from MTA([127.0.0.1]:10025): 250 2.0.0 Ok: queued as 5AEE71715D0)
Feb 18 20:00:20 mail postfix/smtp[27117]: F33E01715C9: to=<brooke_leee@yahoo.com>, relay=127.0.0.1[127.0.0.1]:10024, delay=8.5, delays=2.6/0.01/0.01/5.9, dsn=2.0.0, status=sent (250 2.0.0 Ok, id=13740-01, from MTA([127.0.0.1]:10025): 250 2.0.0 Ok: queued as 5AEE71715D0)
Feb 18 20:00:20 mail postfix/smtp[27117]: F33E01715C9: to=<c0809@yahoo.com>, relay=127.0.0.1[127.0.0.1]:10024, delay=8.5, delays=2.6/0.01/0.01/5.9, dsn=2.0.0, status=sent (250 2.0.0 Ok, id=13740-01, from MTA([127.0.0.1]:10025): 250 2.0.0 Ok: queued as 5AEE71715D0)
Feb 18 20:00:21 mail postfix/qmgr[27047]: F33E01715C9: removed

The "from" and "to" are on different lines and there is another challenge which is that the results should be limited to messages who have 3 or fewer recipients.
I thought it would be easy enough, and I wrote a script that first gets a list of the tag numbers ( F33E01715C9 which belong to messages with 3 or fewer recipients

Needless to say, its not an efficient script, there must be a better way. Please help!! Any responses are appreciated, maybe someone can just point me in the right direction?

Thanks,
Puka

---------- Post updated at 09:52 PM ---------- Previous update was at 01:03 PM ----------

Dear Member,

I want out put.

authen@domain.com | sender@domain | recipient@domain

exam

account1@domain1.com | sender2@domain2.com | brian5841@yahoo.com,brooke_leee@yaho...0809@yahoo.com

or

account1@domain1.com | sender2@domain2.com | brian5841@yahoo.com
account1@domain1.com | sender2@domain2.com | brooke_leee@yahoo.com
account1@domain1.com | sender2@domain2.com | c0809@yahoo.com


Please help to write full script for me by perl or shell.
Regards
Puka
# 2  
Old 05-31-2011
Not good solution, but simple.

Code:
 egrep -o "sasl_username=.*|from=.*|to=.*" infile  |awk '/sasl_username=/{username=$1;i=0}
/from=/{from=$1}
/to=/&&++i<=3{print username, from, $1}' OFS="|" |awk '{gsub(/sasl_username=|from=|to=|<|>|,/,"")}1'


account1@domain1.com|sender2@domain2.com|brian5841@yahoo.com
account1@domain1.com|sender2@domain2.com|brooke_leee@yahoo.com
account1@domain1.com|sender2@domain2.com|c0809@yahoo.com
account1@domain1.com|sender2@domain2.com|brian5841@yahoo.com
account1@domain1.com|sender2@domain2.com|brooke_leee@yahoo.com
account1@domain1.com|sender2@domain2.com|c0809@yahoo.com


Last edited by rdcwayx; 05-31-2011 at 12:22 AM..
This User Gave Thanks to rdcwayx For This Post:
# 3  
Old 05-31-2011
Quote:
Originally Posted by rdcwayx
Not good solution, but simple.

Code:
 egrep -o "sasl_username=.*|from=.*|to=.*" infile  |awk '/sasl_username=/{username=$1;i=0}
/from=/{from=$1}
/to=/&&++i<=3{print username, from, $1}' OFS="|" |awk '{gsub(/sasl_username=|from=|to=|<|>|,/,"")}1'
 
 
account1@domain1.com|sender2@domain2.com|brian5841@yahoo.com
account1@domain1.com|sender2@domain2.com|brooke_leee@yahoo.com
account1@domain1.com|sender2@domain2.com|c0809@yahoo.com
account1@domain1.com|sender2@domain2.com|brian5841@yahoo.com
account1@domain1.com|sender2@domain2.com|brooke_leee@yahoo.com
account1@domain1.com|sender2@domain2.com|c0809@yahoo.com

I generate code but not want out put.

sasl_username=account1@domain1.com
from=<account1@domain1.com>,
from=<account1@domain1.com>,
to=<account1@domain1.com>,
from="avel88@hotmail.com";
from=avel88@hotmail.com,
from=avel88@hotmail.com,
from=<avel88@hotmail.com>,
to=<account2@domain2.com>,
from=<seo1@co.za>
from=<avel88@hotmail.com>,
to=<iam@hotmail.co.th>,
to=<da@hotmail.com>,
to=<account3@domain3.com>,
to=<user1@domain3.com>,
to=<user2@domain3.com>,
to=<user3@domain3.com>,
to=<user4@domain3.com>,

my code

awk ' BEGIN { FS="[" } /client=/ { print $3 } ' < /var/log/mail.log | sed s/]//

22.13.23.200, sasl_method=LOGIN, sasl_username=account1@domain1.com, ........... , .............
33.14.55.243
55.154.173.75
66.15.219.1, sasl_method=LOGIN, sasl_username=account1@domain2.com, ........... , .............
14.12.138.57, sasl_method=LOGIN, sasl_username=account1@domain3.com, ........... , .............

I can not show , ....from=<....... , .....to=<........ , .....to=<........ , .....to=<........ (to 3 account)

or

, ....from=<....... , .....to=<........ (to 1 account)

---------- Post updated at 10:42 PM ---------- Previous update was at 10:37 PM ----------

Quote:
Originally Posted by rdcwayx
Not good solution, but simple.

Code:
 egrep -o "sasl_username=.*|from=.*|to=.*" infile  |awk '/sasl_username=/{username=$1;i=0}
/from=/{from=$1}
/to=/&&++i<=3{print username, from, $1}' OFS="|" |awk '{gsub(/sasl_username=|from=|to=|<|>|,/,"")}1'
 
 
account1@domain1.com|sender2@domain2.com|brian5841@yahoo.com
account1@domain1.com|sender2@domain2.com|brooke_leee@yahoo.com
account1@domain1.com|sender2@domain2.com|c0809@yahoo.com
account1@domain1.com|sender2@domain2.com|brian5841@yahoo.com
account1@domain1.com|sender2@domain2.com|brooke_leee@yahoo.com
account1@domain1.com|sender2@domain2.com|c0809@yahoo.com

if out put

account1@domain1.com | sender2@domain2.com | brian5841@yahoo.com,brooke_leee@yaho...0809@yahoo.com

I wrtie code ?

Thank you very much
# 4  
Old 05-31-2011
Seems from= has multi-instances. My current code doesn't work in this situation.

But continue your question for the new output only:

Code:
egrep -o "sasl_username=.*|from=.*|to=.*" infile  |awk '/sasl_username=/{print username,from,to[username FS from];username=$1;i=0}
/from=/{from=$1}
/to=/&&++i<=3{to[username FS from]=to[username FS from] OFS $1}' OFS="|" |awk '{gsub(/sasl_username=|from=|to=|<|>|,/,"")}1'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can i make my cron/script to generate a log filename with timestamp in it ?

Hello Friends, I would like my script to display date timestamps in the file name for every script execution. Below is the scenario: (just for testing purpose) I scheduled a cron job, lets say it runs every 5 min and record/logs output in to a log file. 0,5,10,15,20,25,30,35,40,45,50,55 *... (5 Replies)
Discussion started by: System Admin 77
5 Replies

2. Shell Programming and Scripting

Perl: script to work with files with the same name in different directories

Hi All, I would like to use a Perl (not Bash) script to work with multiple files of the same name in different directories (all in the same parent directory). I tried to create a loop to do so, but it isn't working. My code so far: while (defined(my $file = glob("./*/filename.txt")) or... (1 Reply)
Discussion started by: elgo4
1 Replies

3. Shell Programming and Scripting

[Fixed Itself!] Sending mail form script using sSMTP does not work

I have installed sSMTP and set it up to use my gmail. Sending from cli does work fine: msg file:From: test@gmail.com To test2@gmail.com Subject: test post This is a test Executing from console:ssmtp -t < msg does work fine. But from script it does not work:#!/bin/sh ssmtp -t < msg... (0 Replies)
Discussion started by: Jotne
0 Replies

4. Shell Programming and Scripting

How to monitor log file for a Error and generate the e-mail ( Please help)

This is my log file and this is live log. Any abnormal error other than following I need to generate the email. Log path : /DER/app/admin/ABC/bdump/erg.log Current log# 2 seq# 103046 mem# 0: /ora2/oradata/ABC/redo02a.log Current log# 2 seq# 103046 mem# 1:... (7 Replies)
Discussion started by: hishanms
7 Replies

5. Shell Programming and Scripting

Monitor log file for a Error and generate the e-mail.

This is my log file and this is live log. Any abnormal error other than following I need to generate the email. Log path : /DER/app/admin/ABC/bdump/erg.log Current log# 2 seq# 103046 mem# 0: /ora2/oradata/ABC/redo02a.log Current log# 2 seq# 103046 mem# 1:... (1 Reply)
Discussion started by: hishanms
1 Replies

6. Shell Programming and Scripting

sed script to generate hyperlinks refuses to work

Hi All, I'm new to the forum and not a programmer, but I'm writing a bash script to preprocess definitions of technical terms by inserting hyperlinks pointing to other pages in the glossary before the pages are posted to our server, using a standard naming convention for the pages. The... (3 Replies)
Discussion started by: markfgilliland
3 Replies

7. Shell Programming and Scripting

perl or bash script that will generate a higher than usual load

Hi, please advise what function in perl or system call in shell that will generate cpu usage that is higher than usual? I would like make such a script, to test a monitoring feature. TIA. Marc (1 Reply)
Discussion started by: marcpascual
1 Replies

8. Shell Programming and Scripting

Modify Perl script to work with txt - Permissions script

Hi I have this code, and i want work with a ls -shalR output in .txt What i need read to do this?? Where start? #!/usr/bin/perl # Allrights- A perl tool for making backups of file permissions # Copyright (C) 2005 Norbert Klein <norbert@acodedb.com> # This program is free... (1 Reply)
Discussion started by: joangopan
1 Replies

9. Shell Programming and Scripting

mail program on shell script didn't work, please advise.

Hi, everyone: I post a new thread because previous post may sink and I hope the new one can be caught by your eyes. I created a shell script and the script works fine. However, the mail program part on script didn't send email to my email box and it also didn't provide any traceable... (7 Replies)
Discussion started by: duke0001
7 Replies

10. Shell Programming and Scripting

Modify script to generate a log file

I've seen several examples of scripts in thise forum about having a script generate a log file. I have a script that is run from cron and that monitors a file system for a specfic filename(s) and then performs some actions on them. Normally I call this script from another script (which the one... (2 Replies)
Discussion started by: heprox
2 Replies
Login or Register to Ask a Question