From owner-freebsd-questions Sun Aug 30 04:11:58 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id EAA13573 for freebsd-questions-outgoing; Sun, 30 Aug 1998 04:11:58 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: (from jmb@localhost) by hub.freebsd.org (8.8.8/8.8.8) id EAA13567; Sun, 30 Aug 1998 04:11:51 -0700 (PDT) (envelope-from jmb) From: "Jonathan M. Bresler" Message-Id: <199808301111.EAA13567@hub.freebsd.org> Subject: Re: Sending Mail to All Users In-Reply-To: from Jason McKay at "Aug 30, 98 05:51:17 pm" To: jasonm@barney.webace.com.au (Jason McKay) Date: Sun, 30 Aug 1998 04:11:51 -0700 (PDT) Cc: questions@FreeBSD.ORG, isp@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL32 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Jason McKay wrote: > > Hello, > > I urgently need to send a message to all users on my FreeBSD system. I > understand there is a way using aliases, and a script that makes up a > listing of all users. > /etc/aliases: everyone: "| /usr/local/bin/mail.everyone" /usr/local/bin/mail.everyone: !/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; } jmb To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message