xref: /openbsd/gnu/usr.bin/cvs/contrib/mfpipe.in (revision d485f761)
1#! @PERL@
2# -*-Perl-*-
3#
4# From: clyne@niwot.scd.ucar.EDU (John Clyne)
5# Date: Fri, 28 Feb 92 09:54:21 MST
6#
7# BTW, i wrote a perl script that is similar to 'nfpipe' except that in
8# addition to logging to a file it provides a command line option for mailing
9# change notices to a group of users. Obviously you probably wouldn't want
10# to mail every change. But there may be certain directories that are commonly
11# accessed by a group of users who would benefit from an email notice.
12# Especially if they regularly beat on the same directory. Anyway if you
13# think anyone would be interested here it is.
14#
15#	File:		mfpipe
16#
17#	Author:		John Clyne
18#			National Center for Atmospheric Research
19#			PO 3000, Boulder, Colorado
20#
21#	Date:		Wed Feb 26 18:34:53 MST 1992
22#
23#	Description:	Tee standard input to mail a list of users and to
24#			a file. Used by CVS logging.
25#
26#	Usage:		mfpipe [-f file] [user@host...]
27#
28#	Environment:	CVSROOT
29#				Path to CVS root.
30#
31#	Files:
32#
33#
34#	Options:	-f file
35#				Capture output to 'file'
36#
37
38$header = "Log Message:\n";
39
40$mailcmd = "| mail -s  'CVS update notice'";
41$whoami = `whoami`;
42chop $whoami;
43$date = `date`;
44chop $date;
45
46$cvsroot = $ENV{'CVSROOT'};
47
48while (@ARGV) {
49        $arg = shift @ARGV;
50
51	if ($arg eq '-f') {
52                $file = shift @ARGV;
53	}
54	else {
55		$users = "$users $arg";
56	}
57}
58
59if ($users) {
60	$mailcmd = "$mailcmd $users";
61	open(MAIL, $mailcmd) || die "Execing $mail: $!\n";
62}
63
64if ($file) {
65	$logfile = "$cvsroot/LOG/$file";
66	open(FILE, ">> $logfile") || die "Opening $logfile: $!\n";
67}
68
69print FILE "$whoami $date--------BEGIN LOG ENTRY-------------\n" if ($logfile);
70
71while (<>) {
72	print FILE $log if ($log && $logfile);
73
74	print FILE $_ if ($logfile);
75	print MAIL $_ if ($users);
76
77	$log = "log: " if ($_ eq $header);
78}
79
80close FILE;
81die "Write failed" if $?;
82close MAIL;
83die "Mail failed" if $?;
84
85exit 0;
86