Uuclean flushing mail requests

kwlalonde at watmath.UUCP kwlalonde at watmath.UUCP
Sat Jan 10 14:41:24 AEST 1987


In article <1364 at pyramid.UUCP> csg at pyramid.UUCP (Carl S. Gutekunst) writes:
>The uucleanup facility of HoneyDanBer (provided by AT&T in System VR2.0.4 and
>beyond) attempts to figure out what an queued item is, and send a warning to
>the real originator. (If you've ever had mail stranded at ihnp4, then you've
>seen the friendly message that HDB sends out.)

Here's a simple program we use to automatically return undelivered uucp mail
to sender, for 4BSD uucp.  It doesn't handle arbitrary uux or uucp requests,
but for us that isn't worth fixing.  Install uubounce in /usr/lib/uucp
and run uu.daily once a day from the cron.

#!/bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #!/bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	uu.daily
#	uubounce.c
# This archive created: Fri Jan  9 23:19:46 1987
# By:	watmath!root (Ken Lalonde)
export PATH; PATH=/bin:$PATH
if test -f 'uu.daily'
then
	echo shar: over-writing existing file "'uu.daily'"
fi
cat << \SHAR_EOF > 'uu.daily'
#!/bin/sh
# Clean up uucp directories.
# Assumes you have subdirectories.

PATH=/usr/lib/uucp:/usr/ucb:/bin:/usr/bin ; export PATH
umask 002

# For mail
NAME=uucp; USER=uucp; export NAME USER

SPOOL=/usr/spool/uucp
OLDEST=30			# files older than 30 days will be cleaned
HOURS=`expr ${OLDEST} '*' 24`
SYSTEM=`uuname -l`

uuclean -pLTMP. -n48
uuclean -d${SPOOL}/TM. -pTM. -n${HOURS}
uuclean -d${SPOOL}/X. -pX. -n${HOURS}
uuclean -d${SPOOL}/C. -pC. -n${HOURS}
uuclean -d${SPOOL}/D.${SYSTEM}X -pD. -n${HOURS}

# Save the D. and D.host stuff in /tmp so we can have a look.

temp1=/tmp/uudaily1$$
temp2=/tmp/uudaily2$$
rm -f $temp2

for dir in ${SPOOL}/D.${SYSTEM} ${SPOOL}/D. ; do
	find $dir -type f -mtime +${OLDEST} -print > $temp1
	if [ $dir = ${SPOOL}/D.${SYSTEM} -a -s $temp1 ]; then
		/usr/lib/uucp/uubounce `cat $temp1`
		find $dir -type f -mtime +${OLDEST} -print > $temp1
	fi
	if [ -s $temp1 ]; then
		mv -f `cat $temp1` /tmp
		cat $temp1 >> $temp2
	fi
done
if [ -s $temp2 ]; then
	Mail -s "$0: Expired files, moved to /tmp" uucp < $temp2
fi
rm -f $temp1 $temp2
SHAR_EOF
chmod +x 'uu.daily'
if test -f 'uubounce.c'
then
	echo shar: over-writing existing file "'uubounce.c'"
fi
cat << \SHAR_EOF > 'uubounce.c'
/*
 * uubounce files ...
 * Attempt to return expired uucp mail files to sender.
 * Returned files are unlinked, non-mail files are left alone.
 * /usr/lib/uucp/uu.daily uses this.
 */

#include <stdio.h>

char *myname;
char  hostname[64];

main(argc, argv)
char **argv;
{
	int i;
	FILE *f;

	myname = argv[0];
	gethostname(hostname, sizeof hostname);	/* should use uuname -l */
	for (i = 1; i < argc; i++) {
		if ((f = fopen(argv[i], "r")) == NULL) {
			Perror("fopen", argv[i]);
			continue;
		}
		bounce(f, argv[i]);
		fclose(f);
	}
	exit(0);
}

bounce(f, fname)
register FILE *f;
char *fname;
{
	register int c;
	register FILE *m;
	char buf[BUFSIZ], addr[BUFSIZ];
	extern FILE *popen();

	if (fgets(buf, sizeof buf, f) == NULL)
		return;
	if (strncmp("From ", buf, 5))
		return;	/* not a mail message */
	if (sscanf(buf+5, "%s", addr) != 1)
		return;	/* ? */
	if (strlen(addr) < 2)
		return;	/* sanity */
	sprintf(buf, "Mail -s 'Returned mail' '%s'", addr);
	if ((m = popen(buf, "w")) == NULL) {
		Perror("popen", buf);
		return;
	}
	fprintf(m,
"We have been unable to deliver the following letter\n\
in a reasonable length of time.\n");
	if (hostname[0])
		fprintf(m, "Sincerely,\n\t%s!uucp\n", hostname);
	putc('\n', m);
	rewind(f);
	while ((c = getc(f)) != EOF)
		putc(c, m);
	if (pclose(m) != 0)
		Perror("pclose", fname);
	else if (unlink(fname) < 0)
		Perror("unlink", fname);
}

Perror(a, b)
	char *a, *b;
{
	fprintf(stderr, "%s: %s: ", myname, a);
	perror(b);
}
SHAR_EOF
#	End of shell archive
exit 0

--
Ken Lalonde, U of Waterloo



More information about the Comp.unix.wizards mailing list