Duplicate Entries and Automation

Ordinarily, duplicate local names on the lefthand side of the colon in an aliases file will result in an error. For example, consider this abstract from an aliases file:

staff: bob
staff: george

Running newaliases on this file would produce the following error message and would cause the first entry to be ignored:

Warning: duplicate alias name george

Sometimes, however, it is advantageous to produce an aliases file with duplicates. Consider this abstract from a script that adds new users:

if [ $GROUP = "staff" ]
then
        echo "staff: $USER" >> /etc/aliasdir/groups
fi

Here, we seek to add the user whose login name is stored in $USER to the mailing list called staff. To prevent sendmail from complaining, we declare the /etc/aliasdir/groups file like this in the configuration file:

define(`ALIAS_FILE', `dbm:-A /etc/aliasdir/groups')

Here, the dbm tells sendmail this is a ndbm(3)-type file (it could also be btree or hash for db(3)-type files). The -A switch tells sendmail to append duplicates rather than rejecting them. To illustrate, revisit the earlier aliases file:

staff: bob
staff: george

The first alias line is read and stored normally with this key and value pair:

staff    bob
↑  ↑
 key      value

The second line is then appended to the first line, because of the -A switch, to form:

staff    bob,george
↑    ↑
 key      value

The comma is intelligently inserted by sendmail.

Although this technique can simplify the maintenance of some alias files, it should not be overused. Each append ...

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.