procmail
[Top] [All Lists]

Error reporting in .maillog

1998-11-02 10:17:37
This might be more of a perl question than a procmail question,
but here goes.

I've written a perl script to notify me by pager whenever I get 
email.  This is useful when I'm waiting for something important
and happen to be in a meeting or whatever, but obviously I don't
want to be awakened at odd hours every time I get email.  In
addition, it's not really necessary when I'm sitting right here 
at my workstation.  So I've included some switches to control the
times and weekdays for which the script will forward email to my
pager, and also a means of manually turning it on and off by 
touching or deleting a file in my home directory.

The interesting thing is this:  when the script terminates without
paging me (because the current time is out of range of the times
during which I wish to be paged, or the "don't page" file exists),
I get error messages in my .maillog and hence in the output of 
mailstat.  This doesn't happen consistently, leading me to believe
it may be due to a lockfile problem or something simlar (note in
the .maillog below there are 5 messages indicated, only 4 of which
caused errors -- if I'm reading it right).

Anyone know why this would be?  And what I could do to fix it?

For reference I've included below the recipe from my .procmailrc that 
forwards email to the script, a sample of the output from mailstat, 
the corresponding .maillog, and the script itself.  The "pager" script 
referenced in the system call in the "mailnotify" script just reformats 
the text and emails it to my pager's email address; I can include that 
too if necessary but I didn't think it would be required for this 
question.

Procmail version is 3.10, perl version is 5.003.  I'm running under
SunOS version 5.5.1.

Thanks in advance for any answers!

##### my .procmailrc #####

SHELL=/bin/sh
VERBOSE=off
MAILDIR=$HOME/Mail
LOGFILE=$HOME/.maillog
#LOGABSTRACT = "all"

[various recipes to handle mailing lists and spam, etc.]

# everything else should go through, but first we send a
# notification via pager

:0 c
| /home/mshaw/bin/mailnotify -number 5981529 -after 8 -before 18 -days MTWRF

##### output of mailstat #####

caravan > mailstat .maillog
 
  Total  Number Folder
  -----  ------ ------
      0       4  ## procmail: Error while writing to 
"/home/mshaw/bin/mailnotify"
  32005       5 /usr/spool/mail/mshaw
caravan >

##### .maillog that produced the above #####

procmail: Error while writing to "/home/mshaw/bin/mailnotify"
From mshaw(_at_)asic(_dot_)sc(_dot_)ti(_dot_)com  Mon Nov  2 10:11:07 1998
 Subject: t2
  Folder: /usr/spool/mail/mshaw                                            6401
procmail: Error while writing to "/home/mshaw/bin/mailnotify"
procmail: Error while writing to "/home/mshaw/bin/mailnotify"
procmail: Error while writing to "/home/mshaw/bin/mailnotify"
From mshaw(_at_)asic(_dot_)sc(_dot_)ti(_dot_)com  Mon Nov  2 10:11:08 1998
 Subject: t5
  Folder: /usr/spool/mail/mshaw                                            6401
From mshaw(_at_)asic(_dot_)sc(_dot_)ti(_dot_)com  Mon Nov  2 10:11:07 1998
 Subject: t1
  Folder: /usr/spool/mail/mshaw                                            6401
From mshaw(_at_)asic(_dot_)sc(_dot_)ti(_dot_)com  Mon Nov  2 10:11:08 1998
 Subject: t3
  Folder: /usr/spool/mail/mshaw                                            6401
From mshaw(_at_)asic(_dot_)sc(_dot_)ti(_dot_)com  Mon Nov  2 10:11:08 1998
 Subject: t4
  Folder: /usr/spool/mail/mshaw                                            6401

##### mailnotify script #####

#!/usr/local/bin/perl -w
#
#   ############################################################################
#                          Property of Texas Instruments
#                       For Unrestricted Internal Use Only
# 
#         Unauthorized reproduction and/or distribution is  strictly  pro-
#         hibited. This product is protected under copyright law and trade
#         secret law as an unpublished work.
# 
#          Created 1998, (C) Copyright 1998 Texas Instruments, Inc.
#                             All rights reserved.
# 
#   ############################################################################
#
# Filename:    mailnotify
# Author:      Mark Shaw (msgid MNS1, mshaw(_at_)asic)
# Purpose:     works with procmail -- sends notification to an alphanumeric 
#              pager whenever email comes in.
#
  $version = 0.5;
#
# History: 
#
#    980813  created.
#    980814  added code to limit times of operation.
#    980825  added code to extract message text from email.
#    980915  changed 'exit' to 'die' for non-usage-error aborts
#            changed code to exploit new <num>@rfsystemsgroup.com addresses
#    980916  changed code back, that address doesn't work well
#            see mailnotify_rf for future use
#    980930  changed 'die' back to 'exit' -- 'die' causes goofy entries
#            in $HOME/.maillog
#    981005  removed non-error exits and replaced with a flag-and-test
#
# Exit values:
#
#    0    normal completion
#    1    usage error
#
# Known bugs and limitations:
#
#    None known as yet.
#
# To do:
#
#    - no plans as yet.
#
#################################################################################

$text = "";
$sender = "";
$subject_line = "";
$number = 0;
$after = 0;
$before = 24;
$days = "NMTWRFS";
$disable_file = "$ENV{'HOME'}/.nomailnotify";
#$maxlength = 225;
$maxlength = 450;
$notify = 1;

sub usage
  {
   print "\n";
   print "usage: mailnotify [options]\n\n";
   print "  legal options are:\n\n";
   print "    -number <phone number>  (default: none, required)\n";
   print "    -after  <integer>       (default: $after)\n";
   print "    -before <integer>       (default: $before)\n";
   print "    -days <string>          (default: $days)\n";
   print "\n";
   print "Contact MNS1 for more information.\n";
   print "version: $version\n\n";
  }

sub interpret_command_line
  {
   for($arg=0; $arg<@ARGV; $arg++)
     {
      if($ARGV[$arg] eq "-number")
        {
         $number = $ARGV[++$arg];
         next;
        }
      elsif($ARGV[$arg] eq "-after")
        {
         $after = $ARGV[++$arg];
         next;
        }
      elsif($ARGV[$arg] eq "-before")
        {
         $before = $ARGV[++$arg];
         next;
        }
      elsif($ARGV[$arg] eq "-days")
        {
         $days = $ARGV[++$arg];
         next;
        }
      else
        {
         &usage;
         exit(1);
        }
     }
  }


# main flow

if(-f $disable_file)  # presence of this file turns off notification
  {
   $notify = 0;
  }

&interpret_command_line;

# get localtime and check against specified operational time

$today = (N,M,T,W,R,F,S)[(localtime)[6]];

if($days !~ /$today/)
  {
   $notify = 0;
  }

$hour = (localtime)[2];

if( ($hour < $after) or ($hour > $before) )
  {
   $notify = 0;
  }

if($notify)
  {
   $number =~ s/\D//g;  # strip out non-digits from phone number

   while(<STDIN>)    # parse mail header -- first blank line separates
     {               # header from message
      chomp;
      if(/^\s*$/)
        {
         last;
        }
      elsif(/^From\s+(\S+)\s*/)
        {
         $sender = $1;
        }
      elsif(/^Subject:\s+.*/)
        {
         $subject_line = $_;
        }
     }
   
   $text = sprintf "email from %s, %s, text: ", $sender, $subject_line;
   
   while(<STDIN>)  # now get message text
     {
      chomp;
      $text = $text . " " . $_;
   
      last if length($text) > $maxlength;
     }
   
   system("/home/mshaw/bin/pager -number $number -text \"$text\"");
  }

<Prev in Thread] Current Thread [Next in Thread>