Extracting Data From Sendmail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting Data From Sendmail
# 1  
Old 01-14-2007
Extracting Data From Sendmail

Hello,

Like many Unix shops, Our systems send Email alerts whenever things break. I have been tasked with writing a shell script to get the email alerts from Sendmail, extract the Date / Time, From, Subject, and message text from the emails and punch them into a MySQL DB. This will then be parsed and used to generate Error Stats and SLA reports.

My problem is I can't seem to find any info or blurb of code on how to extract this info from a Sendmail using a shell script, and my O'Rielly Sendmail book is MIA.

Anyone out there have any expierience with this and/or could guide me in the right direction?


Thanks in Advance,


ChrisA.
# 2  
Old 01-14-2007
I'm not sure I follow what you are trying to do.

Do you mean to process the emails or the sendmail log?
# 3  
Old 01-14-2007
I need to parse the individual emails as they come in, but I am not sure how to extract the data from sendmail. I could have the emails go to a special account, but I dont know how to get the need data out of the emails. If the email can be dumped to a file I could do it that way, but I am not as familiar with Sendmail as I would like.
# 4  
Old 01-15-2007
I think perl can handle that, something like :
Code:
open(MYINPUTFILE, "<filename.in");
open(MYOUTPUTFILE, ">filename.out");
while(<MYINPUTFILE>)
 {
 my($line) = $_;
 chomp($line);
 if($line =~ m|(\d{5})(.{20})(\d\d)/(\d\d)/(\d\d)|)
 {
 my($zip,$name,$mm,$dd,$yy) = ($1,$2,$3,$4,$5);
 if($yy > 10)
 {$yy += 1900}
 else
 {$yy += 2000}
 my($first, $last) = split(/ /, $name);
 $line = sprintf("%-16s%-10s%02d/%02d/%04d%5d",
 $last,$first,$mm,$dd,$yy,$zip);
 print MYOUTPUTFILE "$line\n";
 }
 }
close(MYINPUTFILE);
close(MYOUTPUTFILE);

I took this example from random google page, therefore it does not describe exactly the task you want to achieve, but
open the file, parse the content as defined in regexp and output it in a different file. Then INSERT this in SQL. Also, you need to know where the sendmail store those e-mails, if this is one e-mail, or a single flat file, my example is "/var/spool/mail/root"
This is just a suggestion, there are more efficient ways to achieve that, I believe that someone will post another opinion soon.
Edit : Actually, I believe that Python would be more elegant way to solve this, but i'm not really expirienced with it, ghostdog74 is one of Python's experts here.
Hope this helps.

Last edited by sysgate; 01-15-2007 at 09:04 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with extracting data within parentheses

This is my input file: a|b|c(ef)|g|h(km)|p My output file should look like: a|b|ef|g|km|p That is, pipe is the delimiter. The data within pipe must be displayed as it is but if it encounters any data within parentheses, then only the data within parentheses has to be displayed ( the data... (2 Replies)
Discussion started by: ksatish89
2 Replies

2. UNIX for Dummies Questions & Answers

Extracting data from file

I am trying to compare the data in lines 3 & 5 to see if they match up to the '-S570' (see first code set, all proprietary information has been removed from code set) spawn telnet Trying ... Connected to CA-LOS1234-ASE-S570.cl . Escape character is '^]'. CA-LOS1234-ASE-S570 Username: ... (1 Reply)
Discussion started by: slipshft
1 Replies

3. Shell Programming and Scripting

extracting data

I have a txt file of the following format >ab_ qwerty >rt_ hfjkil >Ty2 hglashglkasghkf; >P2 aklhfklflkkgfgkfl >ui_ vnllkdskkkffkfkkf >we32 vksksjksj;lslsf'sk's's .... ..... I want to split this big file based on the header (>) (5 Replies)
Discussion started by: Lucky Ali
5 Replies

4. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

5. Shell Programming and Scripting

Extracting and printing data

Hi I have the following data : <Cell id="34A" ref="ds:/BTS:34/Cells/Cell:34A"/> <Cell id="34B" ref="ds:/BTS:34/Cells/Cell:34B"/> <Cell id="34C" ref="ds:/BTS:34/Cells/Cell:34C"/> I would like to print this data in the following format : BTS:34 Cell:34A.I'm... (9 Replies)
Discussion started by: Prega
9 Replies

6. UNIX for Dummies Questions & Answers

Help with extracting data and plotting

I have attached a txt file, what I would like to be able to do is: 1. Extract Data from Columns labeled E/N and Ko into a new file 2. Then in the new file I would like to be able to plot E/N on the X axis and Ko on the y axis. 3. Lastly I would like to be able to extract multiple data sets and... (6 Replies)
Discussion started by: gingburg
6 Replies

7. UNIX for Dummies Questions & Answers

Extracting Data Using SED

Given the following text in a file named extract.txt: listenPort:=25 smtpDestination:=2 enableSSL:= I am trying to extract only the value 2 following smtpDestination:= Someone had suggested I use: sed -e "s/^smtpDestination:=\(.*\)$/\1/" extract.txt but this returns: listenPort:=25 2 ... (2 Replies)
Discussion started by: cleanden
2 Replies

8. Shell Programming and Scripting

Extracting data from each line

Hi All I have one file aa.txt like this Change 172453 on 2006/04/26 10:45:45 by cm@cm-ixca-cm-build23 'cmbuild: ixweb-3.10.28.110 ' Change 172362 on 2006/04/26 08:58:47 by cm@cm-ixca-cm-build23 'build failed: ixweb-3.10.28.109' Change 172299 on 2006/04/26 07:39:08 by... (1 Reply)
Discussion started by: csaha
1 Replies

9. Shell Programming and Scripting

Extracting certain data from a sentence

How do I delete text in each line from the first character up to a certain pattern, ie. 'qmuser.' and then delete from the next occurence of a dot to the end of the sentence For example: - LTSB Renewal Notice Travel Pack --- d \qmaster\spool1\qmuser.8664_LM245_20031216094308.ps.0 From this... (7 Replies)
Discussion started by: dbrundrett
7 Replies

10. UNIX for Dummies Questions & Answers

extracting sendmail: error

I'm a newbie trying to update an old sendmail 8.6 to 8.12.3 ftp'ed sendmail.org and got sendmail.8.12.3.tar.gz file size matches but when i: tar xvf sendmail.8.12.3.tar.gz i get: tar: directory checksum error tried getting others... ie. 8.12.2... ftp'ed using binary and saved in... (1 Reply)
Discussion started by: sphiengollie
1 Replies
Login or Register to Ask a Question