<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Script help needed to parse /var/mail files in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219387#M680944</link>
    <description>&lt;!--!*#--&gt;Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt;  Is there a way to modify the script so that it will get every failed recipient? &lt;BR /&gt;&lt;BR /&gt;If you mean like this (using) you data as attached on Jul 8 @ 00:38 :&lt;BR /&gt;&lt;BR /&gt;... while talking to here.com.:&lt;BR /&gt;Final-Recipient: recipient@here.com&lt;BR /&gt;Action: failed&lt;BR /&gt;Status: 5.1.1&lt;BR /&gt;Subject: Returned mail: User unknown&lt;BR /&gt;Date: Thu, 3 Jul 2008 06:17:24 -0400&lt;BR /&gt;From: sender &lt;SENDER&gt;&lt;BR /&gt;To: recipient@here.com&lt;BR /&gt;Problem: Report&lt;BR /&gt;&lt;BR /&gt;... while talking to here.com.:&lt;BR /&gt;Final-Recipient: recipient@here.com&lt;BR /&gt;Action: failed&lt;BR /&gt;Status: 5.1.1&lt;BR /&gt;Subject: Returned mail: User unknown&lt;BR /&gt;Date: Thu, 3 Jul 2008 06:17:26 -0400&lt;BR /&gt;From: sender &lt;SENDER&gt;&lt;BR /&gt;To: recipient@here.com&lt;BR /&gt;Problem: Report&lt;BR /&gt;&lt;BR /&gt;...then use this slightly modified version:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my $step=0;&lt;BR /&gt;my $id=0;&lt;BR /&gt;my $old=1;&lt;BR /&gt;my ($problem, $recipient, $action, $status, $subject, $date, $from, $to, $real_subject ) ;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;#debug print "$step $. $_\n" if $step != $old;&lt;BR /&gt;#debug $old = $step;&lt;BR /&gt;my ($start, $stop);&lt;BR /&gt;if (($start,$stop) = /^--(\S+\.\d+)\S+?(-?-?)\s?$/) {&lt;BR /&gt;if ($start ne $id) { # New ID? Clear all memory&lt;BR /&gt;#debug print "&amp;lt;&amp;lt;&amp;lt; $. $_";&lt;BR /&gt;$id = $start;&lt;BR /&gt;$step =0;&lt;BR /&gt;$date = q(&lt;NO&gt;)."\n";&lt;BR /&gt;$from = q(&lt;NO&gt;)."\n";&lt;BR /&gt;$to = q(&lt;NO&gt;)."\n";&lt;BR /&gt;$recipient = q(&lt;NO&gt;)."\n";&lt;BR /&gt;$action = q(&lt;NO&gt;)."\n";&lt;BR /&gt;$status = q(&lt;NO&gt;)."\n";&lt;BR /&gt;$real_subject = q(&lt;NO&gt;)."\n";&lt;BR /&gt;} else {&lt;BR /&gt;if ($stop) { # Found closing marker&lt;BR /&gt;print $problem, $recipient, $action, $status, $subject, $date, $from, $to, $real_subject, "\n";&lt;BR /&gt;$step = 0; # Done. Start again.&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;if (0==$step) {&lt;BR /&gt;$subject = $_ if/^Subject:/;&lt;BR /&gt;#       next unless /^[ -]+.*permanent fatal.*-\s?$/;&lt;BR /&gt;        next unless /^[ -]+.*fatal error.*-\s?$/;&lt;BR /&gt;        $step++;&lt;BR /&gt;}&lt;BR /&gt;elsif (1==$step) {&lt;BR /&gt;        next unless /^[ -]+Transcript.*-\s?$/;&lt;BR /&gt;        $problem = &amp;lt;&amp;gt;;&lt;BR /&gt;        $step++;&lt;BR /&gt;        }&lt;BR /&gt;elsif (2==$step) {&lt;BR /&gt;        $date = $_ if /^Date:/;&lt;BR /&gt;        $from = $_ if /^From:/;&lt;BR /&gt;        $to = $_ if /^To:/;&lt;BR /&gt;        ($recipient=$_)=~s/(^Final-Recipient:)(?:.+;)(.+)/$1$2/ if /^Final-Recipient:/;&lt;BR /&gt;        $action = $_ if /^Action:/;&lt;BR /&gt;        $status = $_ if /^Status:/;&lt;BR /&gt;        ($real_subject=$_)=~s/^Subject:/Problem:/ if /^Subject:/;&lt;BR /&gt;        }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;/NO&gt;&lt;/NO&gt;&lt;/NO&gt;&lt;/NO&gt;&lt;/NO&gt;&lt;/NO&gt;&lt;/NO&gt;&lt;/SENDER&gt;&lt;/SENDER&gt;</description>
    <pubDate>Fri, 18 Sep 2009 22:18:03 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2009-09-18T22:18:03Z</dc:date>
    <item>
      <title>Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219351#M680908</link>
      <description>Hi gang,&lt;BR /&gt;&lt;BR /&gt;I need a script that will go through /var/mail and pull "pertinent" information about failed email attempts that I can send to some I.S. personnel (info like the from user, the recipient, the subject, and the error message).  I would like to extract only failed sent messages from /var/mail and exclude other messages in the mailboxes.  And I would like to exclude all of the MIME info and that stuff that really is of no "value" to knowing what was sent that did not go.  I would like to have a script that would do this once a day and only show the information I am looking for that was put there the current day (so once they are aware that an email was rejected that they are not notified about it everyday until the mailbox is emptied).  It would also help if this information could be put into a single file (versus creating a file for each entry) and "prettied up" so that I can email it each day.&lt;BR /&gt;&lt;BR /&gt;Something like this would be great....&lt;BR /&gt;&lt;BR /&gt;*********************************&lt;BR /&gt;user1:  &lt;BR /&gt;----- The following addresses had permanent fatal errors -----&lt;BR /&gt;recipient@somewhere.com... User unknown&lt;BR /&gt;Subject: This is my email&lt;BR /&gt;*********************************&lt;BR /&gt;user1:&lt;BR /&gt;----- The following addresses had permanent fatal errors -----&lt;BR /&gt;recipient@somewhere.com... User unknown&lt;BR /&gt;Subject: This is my email&lt;BR /&gt;*********************************&lt;BR /&gt;user2:&lt;BR /&gt;you see where this is going&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Can any of you scripting gurus help me?  (not asking for much am I? LOL)  Thanks a million!!!</description>
      <pubDate>Thu, 19 Jun 2008 17:36:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219351#M680908</guid>
      <dc:creator>TheJuiceman</dc:creator>
      <dc:date>2008-06-19T17:36:27Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219352#M680909</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;What have you attempted thus far?  Why not post what you have and where you're stuck?&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 19 Jun 2008 17:43:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219352#M680909</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-06-19T17:43:53Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219353#M680910</link>
      <description>How about looking in the mail log ?&lt;BR /&gt;&lt;BR /&gt;/var/adm/syslog/mail.log&lt;BR /&gt;&lt;BR /&gt;if it is not on then turn it on with the sylog config ?&lt;BR /&gt;&lt;BR /&gt;Or..  take all the files and email them to the person requesting this and let them parse it on their own ( only joking :)&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 19 Jun 2008 19:50:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219353#M680910</guid>
      <dc:creator>Tim Nelson</dc:creator>
      <dc:date>2008-06-19T19:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219354#M680911</link>
      <description>Hi James,&lt;BR /&gt;&lt;BR /&gt;What I have is VERY crude, but this is basically what I have.  It looks NOTHING like what I have above.  That is what I would LIKE it to look like if possible.  Here's roughly what I have....&lt;BR /&gt;&lt;BR /&gt;                                             find /var/mail -type f -print | xargs egrep -i 'Final-Recipient:|Subject:|THIS IS A WARN&lt;BR /&gt;ING MESSAGE ONLY|YOU DO NOT NEED TO RESEND YOUR MESSAGE|errors|User unknown|User&lt;BR /&gt;-Agent' | egrep -v 'Subject: at|root|cron|Returned' &amp;gt; /tmp/file&lt;BR /&gt;&lt;BR /&gt;Then I check to see if the file exists and then email it.  I pretty it up a little but not enough to make everyone happy.&lt;BR /&gt;   &lt;BR /&gt;</description>
      <pubDate>Thu, 19 Jun 2008 19:50:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219354#M680911</guid>
      <dc:creator>TheJuiceman</dc:creator>
      <dc:date>2008-06-19T19:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219355#M680912</link>
      <description>Hi Tim,&lt;BR /&gt;&lt;BR /&gt;I do have the mail.log enabled, but it does not give enough information for what is needed.  They really need the subject line to be able to track down what did not go out and where it was generated.</description>
      <pubDate>Thu, 19 Jun 2008 20:06:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219355#M680912</guid>
      <dc:creator>TheJuiceman</dc:creator>
      <dc:date>2008-06-19T20:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219356#M680913</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;As Tim hinted, you need to begin by parsing the '/var/adm/syslog/mail.log'.  For example, if I parse one of mine for the word 'error' i find a line that (sanitized) looks like:&lt;BR /&gt;&lt;BR /&gt;Jun 18 19:14:59 6C:myhostname sendmail[5900]: TAA05900: to=somebody@xyz.net', delay=00:01:15, mailer=relay, relay=excpap01.xyz.net, stat=Transient parse error -- message queued for future delivery&lt;BR /&gt;&lt;BR /&gt;*Now*, if in turn, I parse out the '/var/spool/mqueue' file to which this record points ---- that's the "TAA05900" field --- I would find:&lt;BR /&gt;&lt;BR /&gt;ls -l /var/spool/mqueue/*TAA05900&lt;BR /&gt;-rw-------   1 root       mail           283 Jun 18 19:14 /var/spool/mqueue/dfTAA05900&lt;BR /&gt;-rw-------   1 root       mail           494 Jan 18 19:14 /var/spool/mqueue/qfTAA05900&lt;BR /&gt;&lt;BR /&gt;Then, the 'dfTAA05900' file contains the recipient(s) and the subject for which you are looking.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 19 Jun 2008 20:20:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219356#M680913</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-06-19T20:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219357#M680914</link>
      <description>Hi James,&lt;BR /&gt;&lt;BR /&gt;The mqueue only shows items that have not sent.  I need to get information on things that sent but failed.  Is there a similar way to get this information?  Thank you both again!!!&lt;BR /&gt;&lt;BR /&gt;Oh, and I will submit points at the end.  Thanks again.</description>
      <pubDate>Thu, 19 Jun 2008 21:05:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219357#M680914</guid>
      <dc:creator>TheJuiceman</dc:creator>
      <dc:date>2008-06-19T21:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219358#M680915</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; The mqueue only shows items that have not sent.&lt;BR /&gt;&lt;BR /&gt;That would be true.  Messages remain in this queue (directory) until they are successfull sent, at which time they are then removed.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 19 Jun 2008 21:39:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219358#M680915</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-06-19T21:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219359#M680916</link>
      <description>Hi again,&lt;BR /&gt;&lt;BR /&gt;Yeah, I need to get messages that leave the server but do not get delivered due to things like the recipient is not valid, etc.  /var/mail will populate with this information.  I just need a way to sort through the mail and put it in a user friendly form.</description>
      <pubDate>Thu, 19 Jun 2008 21:45:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219359#M680916</guid>
      <dc:creator>TheJuiceman</dc:creator>
      <dc:date>2008-06-19T21:45:43Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219360#M680917</link>
      <description>Again I don't have access to a system to test this but....&lt;BR /&gt;&lt;BR /&gt;Can you cross reference the failure messages in the mail.log file with the users mbox on the server?&lt;BR /&gt;&lt;BR /&gt;I'm assuming sent mail is stored in the users mailbox.  &lt;BR /&gt;&lt;BR /&gt;So if you have the users name you know the users mailbox.  The mailbox is a text file so you could search their mailbox for the original message.&lt;BR /&gt;&lt;BR /&gt;I'm made a few assumptions.  Hope they apply to your environment.&lt;BR /&gt;&lt;BR /&gt;Cheers</description>
      <pubDate>Fri, 20 Jun 2008 06:32:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219360#M680917</guid>
      <dc:creator>OFC_EDM</dc:creator>
      <dc:date>2008-06-20T06:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219361#M680918</link>
      <description>Found this in the sendmail.cf readme.  I've never used this setting so I don't know if it's what you need.&lt;BR /&gt;&lt;BR /&gt;But at first glance it shows potential&lt;BR /&gt;&lt;BR /&gt;confDEAD_LETTER_DROP DeadLetterDrop &lt;BR /&gt;&lt;BR /&gt;[undefined] Filename to save bounce messages which could not be returned to the user or sent to postmaster. If not set, the queue file will be renamed.&lt;BR /&gt;&lt;BR /&gt;I got this information from&lt;BR /&gt;&lt;A href="http://www.sendmail.org/m4/tweaking_config.html" target="_blank"&gt;http://www.sendmail.org/m4/tweaking_config.html&lt;/A&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 20 Jun 2008 06:50:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219361#M680918</guid>
      <dc:creator>OFC_EDM</dc:creator>
      <dc:date>2008-06-20T06:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219362#M680919</link>
      <description>Well, the big problem isn't finding the messages.  They are in /var/mail.  The problem is when you look at them, there is a bunch of MIME information and stuff that the average user can't make heads or tails out of.  All they want to know is 1) who sent an email that got bounced back 2) what was the email and 3) who was it suppose to go to.  Doing the cross-referencing thing doesn't seem to get me anything more than I can get directly from /var/mail.  I just need a way to get a user friendly way of pulling out the information they want.</description>
      <pubDate>Fri, 20 Jun 2008 21:13:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219362#M680919</guid>
      <dc:creator>TheJuiceman</dc:creator>
      <dc:date>2008-06-20T21:13:09Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219363#M680920</link>
      <description>&lt;!--!*#--&gt;Well, you'll have to learn about the mail file layout. I never seriously looked at it, but it looks recognizable allright.&lt;BR /&gt;&lt;BR /&gt;A script would have to look for stuff 'in order' as well as 'carefully'.&lt;BR /&gt;&lt;BR /&gt;For example, it is not really interested in a line with "Subject:" unless it is at the start of a line, and not until it has seen a line with "permanent failure".&lt;BR /&gt;So the grep needs to be with 'anchored' strings as not to trigger on seemingly right pieces of strings in the wrong place.&lt;BR /&gt;&lt;BR /&gt;The script will probably have to protect itself again NOT finding what it expects, and reset itself instead of blindly looking for strings which are not going to come anymore.&lt;BR /&gt;&lt;BR /&gt;There are many, many ways to do this.&lt;BR /&gt;Below a sample implementation using perl and using a 'step' variable to remember what it is looking for next.&lt;BR /&gt;&lt;BR /&gt;It works on my mail file, as per below.&lt;BR /&gt;&lt;BR /&gt;It might only work on my mail file.&lt;BR /&gt;That's for you to find out.&lt;BR /&gt;And you would need to tweak it to go over all mail files, and format the report 'just so'. (That part is 'work', which I will gladly do.. for the right compensation. :-)&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;$ perl permanent_fatal.pl /var/mail/hein&lt;BR /&gt;550 5.1.2 hein@nnosuchdomain.xyz... Host unknown (Name server: nosuchdomain.xyz: host not found)&lt;BR /&gt;Use of uninitialized value in print at permanent_fatal.pl line 29, &amp;lt;&amp;gt; line 75.&lt;BR /&gt;From: Hein van den Heuvel &lt;HEIN&gt;&lt;BR /&gt;Date: Fri, 20 Jun 2008 21:15:29 -0400 (EDT)&lt;BR /&gt;&lt;BR /&gt;550 5.1.2 hein@wergfwegwe.org... Host unknown (Name server: wergfwegwe.org: host not found)&lt;BR /&gt;Subject: this is a test subject&lt;BR /&gt;From: Hein van den Heuvel &lt;HEIN&gt;&lt;BR /&gt;Date: Fri, 20 Jun 2008 21:20:18 -0400 (EDT)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;$ cat permanent_fatal.pl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my $step=0;&lt;BR /&gt;my $id=0;&lt;BR /&gt;my $old=1;&lt;BR /&gt;my ($problem, $subject, $from, $date);&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;#debug  print "$step $.\n" if $step != $old;&lt;BR /&gt;#debug  old = $step;&lt;BR /&gt;  if (0==$step) {&lt;BR /&gt;     next unless /^   --.*permanent fatal.*-$/;&lt;BR /&gt;     $step++;&lt;BR /&gt;     }&lt;BR /&gt;  elsif (1==$step) {&lt;BR /&gt;     next unless /^   ----- Transcript.*-$/;&lt;BR /&gt;     $problem = &amp;lt;&amp;gt;;&lt;BR /&gt;     $step++;&lt;BR /&gt;     }&lt;BR /&gt;  elsif (2==$step) {&lt;BR /&gt;     next unless /^--(\S+)$/;&lt;BR /&gt;     $id = $1;&lt;BR /&gt;     $step++;&lt;BR /&gt;     }&lt;BR /&gt;  elsif (3==$step) {&lt;BR /&gt;     $subject = $_ if /^Subject:/;&lt;BR /&gt;     $from    = $_ if /^From:/;&lt;BR /&gt;     $date    = $_ if /^Date:/;&lt;BR /&gt;     if (/^--${id}--$/) {&lt;BR /&gt;       print $problem, $subject, $from, $date, "\n";&lt;BR /&gt;       $step = 0; # NOT confused. Done. Start again.&lt;BR /&gt;       }&lt;BR /&gt;     if (/^--(\S+)$/) {&lt;BR /&gt;       $step = 0 unless $1 eq $id ; # Confused? Start again.&lt;BR /&gt;       }&lt;BR /&gt;     }&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;&lt;/HEIN&gt;&lt;/HEIN&gt;</description>
      <pubDate>Sat, 21 Jun 2008 01:53:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219363#M680920</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-06-21T01:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219364#M680921</link>
      <description>Oh, and in case you wonder about:&lt;BR /&gt;&lt;BR /&gt;"Use of uninitialized value in print at permanent_fatal.pl line 29, &amp;lt;&amp;gt; line 75."&lt;BR /&gt;&lt;BR /&gt;That is thanks to 'use warnings'.&lt;BR /&gt;The first refused message had no 'subject' line, so the $subjetc variable was not set up. A real solution would have to protect against that, reseting all message data after a print. Easy enough, but it needs to be done.&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 21 Jun 2008 02:22:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219364#M680921</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-06-21T02:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219365#M680922</link>
      <description>Thanks Hein.  I'm looking at your code and it is all pretty greek to me.  Here is an example of what a returned mail might look like in /var/mail.  Each message is separated by the line "From MAILER-DAEMON..." &lt;BR /&gt;&lt;BR /&gt;From MAILER-DAEMON@domain.com Mon Jun 23 16:36:14 EDT 2008                 &lt;BR /&gt;Received: from localhost (localhost)                                            &lt;BR /&gt;        by local.domain.com (8.9.3 (PHNE_35950)/8.9.3) with internal id Q&lt;BR /&gt;AB24698;                                                                        &lt;BR /&gt;        Mon, 23 Jun 2008 16:36:14 -0400 (EDT)                                   &lt;BR /&gt;Date: Mon, 23 Jun 2008 16:36:14 -0400 (EDT)                                     &lt;BR /&gt;From: Mail Delivery Subsystem &lt;MAILER-DAEMON&gt;                   &lt;BR /&gt;Message-Id: &amp;lt;200806232036.QAB24698@local.domain.com&amp;gt;                     &lt;BR /&gt;To: sender@local.domain.com                                                 &lt;BR /&gt;MIME-Version: 1.0                                                               &lt;BR /&gt;Content-Type: multipart/report; report-type=delivery-status;                    &lt;BR /&gt;        boundary="QAB24698.1214253374/local.domain.com"                  &lt;BR /&gt;Subject: Returned mail: User unknown                                            &lt;BR /&gt;Auto-Submitted: auto-generated (failure)                                        &lt;BR /&gt;                                                                                &lt;BR /&gt;This is a MIME-encapsulated message                                             &lt;BR /&gt;                                                                                &lt;BR /&gt;--QAB24698.1214253374/local.domain.com                                   &lt;BR /&gt;                                                                                &lt;BR /&gt;The original message was received at Mon, 23 Jun 2008 16:36:14 -0400 (EDT)      &lt;BR /&gt;from sender@localhost                                                              &lt;BR /&gt;                                                                                &lt;BR /&gt;   ----- The following addresses had permanent fatal errors -----               &lt;BR /&gt;recipient@local.domain.com                                                &lt;BR /&gt;                                                                                &lt;BR /&gt;   ----- Transcript of session follows -----                                    &lt;BR /&gt;550 recipient@local.domain.com... User unknown                            &lt;BR /&gt;                                                                                &lt;BR /&gt;--QAB24698.1214253374/local.domain.com                                   &lt;BR /&gt;Content-Type: message/delivery-status                                           &lt;BR /&gt;                                                                                &lt;BR /&gt;Reporting-MTA: dns; local.domain.com                                     &lt;BR /&gt;Arrival-Date: Mon, 23 Jun 2008 16:36:14 -0400 (EDT)                             &lt;BR /&gt;                                                                                &lt;BR /&gt;Final-Recipient: RFC822; recipient@local.domain.com                       &lt;BR /&gt;Action: failed                                                                  &lt;BR /&gt;Status: 5.1.1                                                                   &lt;BR /&gt;Last-Attempt-Date: Mon, 23 Jun 2008 16:36:14 -0400 (EDT)                        &lt;BR /&gt;                                                                                &lt;BR /&gt;--QAB24698.1214253374/local.domain.com                                   &lt;BR /&gt;Content-Type: message/rfc822                                                    &lt;BR /&gt;                                                                                &lt;BR /&gt;Return-Path: &lt;SENDER&gt;                                                              &lt;BR /&gt;Received: (from sender@localhost)                                                  &lt;BR /&gt;        by local.domain.com (8.9.3 (PHNE_35950)/8.9.3) id QAA24698;      &lt;BR /&gt;        Mon, 23 Jun 2008 16:36:14 -0400 (EDT)                                   &lt;BR /&gt;Date: Mon, 23 Jun 2008 16:36:13 -0400                                           &lt;BR /&gt;From: Sender's Name &lt;SENDER&gt;                            &lt;BR /&gt;To: recipient@foreigndomain.com            &lt;BR /&gt;Subject: Email subject                                              &lt;BR /&gt;Message-ID: &amp;lt;20080623203613.GA24696@local.domain.com&amp;gt;                    &lt;BR /&gt;Mime-Version: 1.0                                                               &lt;BR /&gt;Content-Type: multipart/mixed; boundary="qDbXVdCdHGoSgWSk"                      &lt;BR /&gt;Content-Disposition: inline                                                     &lt;BR /&gt;User-Agent: Mutt/1.4.2.1i                                                       &lt;BR /&gt;                                                                                &lt;BR /&gt;                                                                                &lt;BR /&gt;--qDbXVdCdHGoSgWSk                                                              &lt;BR /&gt;Content-Type: text/plain; charset=us-ascii                                      &lt;BR /&gt;Content-Disposition: inline                                                     &lt;BR /&gt;                                             Body of email&lt;BR /&gt;                              &lt;BR /&gt;--qDbXVdCdHGoSgWSk                                                              &lt;BR /&gt;Content-Type: text/html; charset=us-ascii                                       &lt;BR /&gt;Content-Disposition: attachment; filename="attachment.htm"                        &lt;BR /&gt;                                                                                &lt;BR /&gt;                                                                          &lt;BR /&gt;                                                             &lt;BR /&gt;                                                                         &lt;BR /&gt;                                                                                &lt;BR /&gt;--qDbXVdCdHGoSgWSk--                                                            &lt;BR /&gt;                                                                                &lt;BR /&gt;--QAB24698.1214253374/local.domain.com--                                 &lt;BR /&gt;                                                                                &lt;BR /&gt;                                                                                &lt;BR /&gt;From MAILER-DAEMON@local.domain.com Mon Jun 23 16:36:14 EDT 2008  &lt;BR /&gt;&lt;BR /&gt;How can I modify the script to look for information the user would want like ...&lt;BR /&gt;&lt;BR /&gt;Subject: Returned mail: User unknown &lt;BR /&gt;From: Sender's Name &lt;SENDER&gt;    &lt;BR /&gt;To: recipient@foreigndomain.com            &lt;BR /&gt;Subject: Email subject  &lt;BR /&gt;&lt;BR /&gt;Thanks again.&lt;/SENDER&gt;&lt;/SENDER&gt;&lt;/SENDER&gt;&lt;/MAILER-DAEMON&gt;</description>
      <pubDate>Mon, 23 Jun 2008 23:48:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219365#M680922</guid>
      <dc:creator>TheJuiceman</dc:creator>
      <dc:date>2008-06-23T23:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219366#M680923</link>
      <description>&amp;gt;&amp;gt; I'm looking at your code and it is all pretty greek to me. &lt;BR /&gt;&lt;BR /&gt;If it was easy you would have had many more replies -). There are several lines starting with "From:" and "Subject:"... which ones to pick.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; Here is an example of what a returned mail might look like in /var/mail. &lt;BR /&gt;&lt;BR /&gt;Thanks. Cut&amp;amp;paste into the forum drops spaces, and maybe added spaces as the line end. I adapted my example to tolerate that, but an 'attached' text file would have been better.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; Each message is separated by the line "c..." &lt;BR /&gt;&lt;BR /&gt;That's what you observe/say. And it may be true. But like I said I knew nothing about the Email format and decided to trigger on the 'permanent fatal' line. :-). I thought, rightly or wrongly so, that those might perhaps come from other sources and also that maybe MAILER-DEAMON might send out other type message which need not be considered. &lt;BR /&gt;&lt;BR /&gt;I changed the cript some to be more clear about looking for 'id' lines. In your case:&lt;BR /&gt;--QAB24698.1214253374/local.domain.com&lt;BR /&gt;--QAB24698.1214253374/local.domain.com--&lt;BR /&gt;&lt;BR /&gt;Try it. Maybe it does what you want, maybe not. It works for me on your example and my file.&lt;BR /&gt;&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my $step=0;&lt;BR /&gt;my $id=0;&lt;BR /&gt;my $old=1;&lt;BR /&gt;my ($problem, $subject, $from, $to, $real_subject);&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;#debug print "$step $.\n" if $step != $old;&lt;BR /&gt;#debug $old = $step;&lt;BR /&gt;&lt;BR /&gt;  if (/^--(\S+\/\S+?)(-?-?)\s?$/) {&lt;BR /&gt;     if ($1 ne $id) { # New ID? Clear all memory&lt;BR /&gt;       $id   = $1;&lt;BR /&gt;       $step = 0;&lt;BR /&gt;       $from =         q(&lt;NO&gt;)."\n";&lt;BR /&gt;       $to =           q(&lt;NO&gt;)."\n";&lt;BR /&gt;       $real_subject = q(&lt;NO&gt;)."\n";&lt;BR /&gt;     } else {&lt;BR /&gt;       if ($2) { # Found closing marker&lt;BR /&gt;         print $problem, $subject, $from, $to, $real_subject, "\n";&lt;BR /&gt;         $step = 0; # Done. Start again.&lt;BR /&gt;       }&lt;BR /&gt;     }&lt;BR /&gt;  }&lt;BR /&gt;  if (0==$step) {&lt;BR /&gt;     $subject = $_ if /^Subject:/;&lt;BR /&gt;     next unless /^[ -]+.*permanent fatal.*-\s?$/;&lt;BR /&gt;     $step++;&lt;BR /&gt;  }&lt;BR /&gt;  elsif (1==$step) {&lt;BR /&gt;     next unless /^[ -]+Transcript.*-\s?$/;&lt;BR /&gt;     $problem = &amp;lt;&amp;gt;;&lt;BR /&gt;     $step++;&lt;BR /&gt;  }&lt;BR /&gt;  elsif (2==$step) {&lt;BR /&gt;     $from  = $_ if /^From:/;&lt;BR /&gt;     $to    = $_ if /^To:/;&lt;BR /&gt;     $real_subject = $_ if /^Subject:/;&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;&lt;/NO&gt;&lt;/NO&gt;&lt;/NO&gt;</description>
      <pubDate>Tue, 24 Jun 2008 07:37:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219366#M680923</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-06-24T07:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219367#M680924</link>
      <description>Hello Hein,&lt;BR /&gt;&lt;BR /&gt;Sorry for the delay getting back.  The updated script seems to be on the right track!!!  I'm just wanting and checking for variations that I need to address.  So far this is a good start!!!  I will report my progress and reward points very soon.  Thank you for your help</description>
      <pubDate>Wed, 25 Jun 2008 21:32:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219367#M680924</guid>
      <dc:creator>TheJuiceman</dc:creator>
      <dc:date>2008-06-25T21:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219368#M680925</link>
      <description>Hello Hein,&lt;BR /&gt;&lt;BR /&gt;The first script seemed to work, it just did not get everything.  The second one I am getting errors such as...&lt;BR /&gt;&lt;BR /&gt;./permanent_fatal.pl[2]: use:  not found.                                       &lt;BR /&gt;./permanent_fatal.pl[3]: use:  not found.                                       &lt;BR /&gt;./permanent_fatal.pl[4]: my:  not found.                                        &lt;BR /&gt;./permanent_fatal.pl[5]: my:  not found.                                        &lt;BR /&gt;./permanent_fatal.pl[6]: my:  not found.                                        &lt;BR /&gt;./permanent_fatal.pl[7]: Syntax error at line 7 : `(' is not expected.  &lt;BR /&gt;&lt;BR /&gt;Can you send the script as an attachment so I can make sure it is correct?  Thanks again.</description>
      <pubDate>Wed, 02 Jul 2008 21:48:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219368#M680925</guid>
      <dc:creator>TheJuiceman</dc:creator>
      <dc:date>2008-07-02T21:48:14Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219369#M680926</link>
      <description>Hi :&lt;BR /&gt;&lt;BR /&gt;&amp;gt; The first script seemed to work, it just did not get everything. The second one I am getting errors such as...&lt;BR /&gt;&lt;BR /&gt;You need to put the "shebang" line at the head so that the Perl interpreter is used:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;&lt;BR /&gt;...assuming that '/usr/bin/perl' is where your Perl lives or is a symbolic link to it.&lt;BR /&gt;&lt;BR /&gt;Without this, the shell thinks it is going to run another shell script.  Hence the shell interpreter stumbles and chokes on the "my" and "use" tokens!&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 02 Jul 2008 22:15:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219369#M680926</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-07-02T22:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: Script help needed to parse /var/mail files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219370#M680927</link>
      <description>You can also run the script from the command line by using perl as the interpreter, such as:&lt;BR /&gt;&lt;BR /&gt;# perl permanent_fatal.pl /var/mail/hein&lt;BR /&gt;&lt;BR /&gt;(This was taken from Hein's first post.)</description>
      <pubDate>Wed, 02 Jul 2008 22:20:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-needed-to-parse-var-mail-files/m-p/4219370#M680927</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2008-07-02T22:20:54Z</dc:date>
    </item>
  </channel>
</rss>

