Batch Rule-Set Testing

The output that is produced by sendmail can become huge, especially when many addresses need testing. To simplify the process (and to help bulletproof your configuration file), consider using a shell script such as the following:

#!/bin/sh
/usr/sbin/sendmail -bt < $1 |\
         egrep "canonify.*input:|canonify.*returns|^>"

Here, the output is piped through egrep(1), which selects only the lines of interest. If this script were to be called testcf.sh, it could be invoked with the following command line:

% testcf.sh address.list

Here, the address.list is a file consisting of pairs of rule set names and addresses such as the following:

canonify,parse nobody@ourhost
canonify,parse nobody@ourhost.domain
canonify,parse nobody@distant.domain
 ... and so on

The output that is produced shows the input to the canonify rule set 3 and the result of each pass through that rule set:

> canonify           input: nobody @ ourhost
canonify         returns: nobody < @ ourhost . domain . >
> canonify           input: nobody @ ourhost . domain
canonify         returns: nobody < @ ourhost . domain . >
> canonify           input: nobody @ distant . domain
canonify         returns: nobody < @ distant . domain . >

Note that the address.list file should contain every conceivable kind of address. The output from the shell script should be saved. At a later time, after the configuration file is changed, diff(1) can be used to see whether the saved output differs from the new output (to see whether anything unexpected changed as a result of your modifications). ...

Get sendmail, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.