From owner-freebsd-questions Thu Oct 12 18:00:28 1995 Return-Path: owner-questions Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id SAA07425 for questions-outgoing; Thu, 12 Oct 1995 18:00:28 -0700 Received: from kryten.atinc.com (kryten.Atinc.COM [198.138.38.7]) by freefall.freebsd.org (8.6.12/8.6.6) with ESMTP id SAA07418 for ; Thu, 12 Oct 1995 18:00:24 -0700 Received: (jmb@localhost) by kryten.atinc.com (8.6.9/8.3) id UAA08290; Thu, 12 Oct 1995 20:48:01 -0400 Date: Thu, 12 Oct 1995 20:47:59 -0400 (EDT) From: "Jonathan M. Bresler" Subject: CORRECTION to perl script To: David Brockus cc: freebsd-questions@freebsd.org Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-questions@freebsd.org Precedence: bulk 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 ( ) { 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 ( ) { $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