Date: Thu, 12 Oct 1995 20:47:59 -0400 (EDT) From: "Jonathan M. Bresler" <jmb@kryten.Atinc.COM> To: David Brockus <dbrockus@cyberhall.com> Cc: freebsd-questions@freebsd.org Subject: CORRECTION to perl script Message-ID: <Pine.3.89.9510122037.A8016-0100000@kryten.atinc.com>
next in thread | raw e-mail | index | archive | help
earlier today i posted a perl script that forwards mail to all users on a host. i erred in that script. (see jordan, it is catching) open( MAIL, "| /usr/bin/mail -s \"$header{'Subject'}\" jmb ); should have been open( MAIL, "| /usr/bin/mail -s \"$header{'Subject'}\" $targets"); add to /etc/aliases: everyone: "| /usr/local/bin/mail.everyone" [B or whereever you have placed the script here is another copy of the corrected script: #!/usr/bin/perl # # collect a mail message from STDIN # edit headers # send it out to everyone on this machine # # # set these to match your system # $debug = 0; $mailcmd = "/usr/bin/mail"; # # list all your non-user accounts here # %daemons = ( "root", 1, "toor", 1, "daemon", 1, "operator", 1, "bin", 1, "games", 1, "man", 1, "uucp", 1, "ingres", 1, "falcon", 1, "nobody", 1 ); # # collect the list of people # to receive the mail message # while ( $user = getpwent ) { (! $daemons{$user} ) && $targets .= " $user"; } # # collect the headers # junk lines that we dont need or want # while ( <STDIN> ) { last if ( /^$/o ); # end of headers next if ( /^Received: /o ); # remove these next if ( /^From /o ); # remove this line if ( ( $key, $value ) = ( /^(\S+):\s*(.*)/ ) ) { ; } $header{$key} = $value; } if ( $debug ) { open( OUT, "> /tmp/mailcatcher.$$") || die("$0 can't open output file"); foreach $key ( sort keys(%header) ) { print OUT "$key = $header{$key}\n" ; } } open( MAIL, "| /usr/bin/mail -s \"$header{'Subject'}\" $targets"); # # do the real work # while ( <STDIN> ) { $debug && print OUT; print MAIL; } Jonathan M. Bresler jmb@kryten.atinc.com | Analysis & Technology, Inc. FreeBSD Postmaster jmb@FreeBSD.Org | 2341 Jeff Davis Hwy play go. | Arlington, VA 22202 ride bike. hack FreeBSD.--ah the good life | 703-418-2800 x346
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.3.89.9510122037.A8016-0100000>