#! /usr/local/bin/perl
#
# Usage: dupalias
# dupalias produces a sorted file containing the contents of the real2alias
# database, then scans it for adjacent lines containing the same alias. It
# reports duplicate aliases on stdout. When it is finished, it deletes the
# file containing the sorted database records.
#
# You should probably run dupalias once a day to make sure nothing has
# gotten screwed up in the alias assignment area. The only time this happened
# to me was because I deleted the lock file when unspool was running, and
# a second one started up, resulting in a dozen duplicate aliases, which
# were subsequently lost.

umask 0077;
system("/usr/personals/listr2a | sort >sorted");
open(SORTED,"<sorted") || die "can't open sorted: $!\n";

$prevalias = '';
while (<SORTED>) {
	($key,$value) = split(/:/);
	if ( "$key" eq "$prevalias") {
		print "duplicate alias: $key\n";
	}
	$prevalias = $key;
}
unlink("sorted");
exit(0);
