procmail
[Top] [All Lists]

Re: procmail diagnostic shell script?

2001-12-16 00:09:35
On 15 Dec, Professional Software Engineering wrote:
| 
| A very basic question posed to the list this morning got me wondering again 
| about producing a script that would attempt to collect up most of the basic 
| data about a configuration - not parsting the user's .procmailrc mind you, 
| but getting user and group info, procmail and formail versions and paths, 
| sendmail version and path (and Mlocal setting), and permissions on 
| particular files and directories of import.
| 
| An initial version of this shell script is at:
|       <http://www.professional.org/procmail/procdiag.sh>
| 
| [...]
| 
| Is there a standard utility or a ready-made script that will report file 
| permissions in numeric format?
| 
| Feedback would be appreciated [...]

A couple of first thoughts.

dmesg |head -1 may not reliably do what you expect. Two of my linux
boxes have replaced the boot messages in the buffer with other kernel
messages. Maybe that's because my kernel logging and syslog config are
foobar, but it seems less than reliable. Isn't uname a standard unix
utility, making it a candidate where portability matters?

This one's a minor nit, but I'd replace the procmail|fgrep|sed pipeline
that assigns to mymailbox with:

mymailbox=`procmail -v 2>&1 |awk '/system mailbox/ {print $NF}'`

It's one less process, minor (and imprecisely observed) performance
gain, and (possibly most important) one less wrapped line. ;-)

As far as reporting permissions in numeric format, the following will do
it. I'm not sure if it's close to what you had in mind, but it allows
you to get rid of the LSCMD contortion. Since this presumably only
needs to run on *nix and you're already assuming perl is available, it
might be reasonable.

#!/usr/local/bin/perl -w
use strict;
while( my $file = shift )
{
   unless( -r $file ) 
   { 
      warn "$file: file not found or insufficient permission\n";
      next;
   }
   my @s = (stat _)[2..9];
   $s[0] = unpack("x2A4",sprintf("%06o",$s[0]));
   $s[2] = getpwuid($s[2]);
   $s[3] = getgrgid($s[3]);  
   splice(@s,4,1);
   splice(@s,5,1);
   $s[5] = scalar localtime($s[5]);
   printf "%04d %2d %-8s %-8s %7d %s %s\n", @s, $file;
}

With minimal testing, I'll say that it should work as a seamless
replacement for LSCMD. It follows symbolic links automatically as
you're doing with ls -L so it works there too (but could be changed by
tesing for links and doing lstat). You might need/want to change the %2d
to %3d for the hard link count in the printf format string.

I've been wracking my brain on the sendmail stuff but haven't come up
with anything. I have no experience with postfix, exim, etc. so can't be
any help there. But speaking of sendmail, you might need a better way
of finding it. On my systems it's executable by "normal" users, but the
directory is not in their PATH by default. It'd be ridiculous to do a
recursive find from /, but maybe something like:

if ! SENDMAIL=`type -p sendmail`; then    # or which if that's better
   SENDMAIL=`find /usr/*bin/ -type f -name sendmail -print 2>/dev/null`
fi
if [ -x "$SENDMAIL" ]; then
   $LSCMD -L $SENDMAIL
   $SENDMAIL -d0 < /dev/null | fgrep -vi "Recipient names"
fi

Don Hammond

-- 
Reply to list please, or append "6" to "procmail" in address if you must.
Spammers' unrelenting address harvesting forces me to this...reluctantly.


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail