Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 30 Aug 1998 04:11:51 -0700 (PDT)
From:      "Jonathan M. Bresler" <jmb>
To:        jasonm@barney.webace.com.au (Jason McKay)
Cc:        questions@FreeBSD.ORG, isp@FreeBSD.ORG
Subject:   Re: Sending Mail to All Users
Message-ID:  <199808301111.EAA13567@hub.freebsd.org>
In-Reply-To: <Pine.BSF.3.96.980830174917.6214A-100000@barney.webace.com.au> from Jason McKay at "Aug 30, 98 05:51:17 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
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 ( <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;
}



jmb

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199808301111.EAA13567>