From owner-freebsd-isp Wed Feb 19 12:45:28 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id MAA17472 for isp-outgoing; Wed, 19 Feb 1997 12:45:28 -0800 (PST) Received: from ns.mexcom.net (root@ns.mexcom.net [206.103.64.9]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id MAA17457 for ; Wed, 19 Feb 1997 12:45:20 -0800 (PST) Received: from sunix (eculp@sunix.mexcom.net [206.103.64.3]) by ns.mexcom.net (8.7.5/8.6.9) with SMTP id OAA21696; Wed, 19 Feb 1997 14:44:44 -0600 Message-ID: <330B6645.56B25411@mexcom.net> Date: Wed, 19 Feb 1997 14:44:53 -0600 From: Edwin Culp Organization: Mexico Communicates, S.C. X-Mailer: Mozilla 3.01Gold (X11; I; Linux 2.0.14 i586) MIME-Version: 1.0 To: Chris Shenton CC: isp@freebsd.org Subject: Re: Script to send mail to all users? References: <199702191758.UAA12437@magrathea.chance.ru> <199702191927.OAA20877@absinthe.i3inc.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-isp@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Chris Shenton wrote: > > Thanks for the suggestions. Some iterated on the users, one message > per user; another cut the names and submitted that as part of the > command but I was concerned that the recipients would see all the > usernames and that the command line might be too long; a couple > suggested Qualcomm's pop bulletin board. > > I finally went with a little program which used awk to create a file > with all users, then modifying /etc/aliases to use this. This avoids > users having to see thousands of names on the To: line, sending > multiple messages, and long command (or /etc/aliases) lines; it also > allows us to use whatever mail client to send the message, rather than > putting a message in a file. > > It requires that you generate the new list of aliases to ensure the > list is current, but it's trivial. FYI, here's what I did: > > /etc/aliases: > > allusers: :include:/etc/aliases.allusers > > /usr/local/bin/makeallusers: > > #!/bin/sh > # $Id: makeallusers,v 1.1 1997/02/19 19:20:56 chris Exp $ > # > # Create a list of all (real) users, one per line, to be used as a > # mail alias via an :include: directive. > ############################################################################### > > cat /etc/passwd | awk -F':' '{print $1}' | egrep -v '^(root|toor|daemon|operator|bin|games|news|man|uucp|xten|nobody|ftp)$' > /etc/aliases.allusers A little easier: awk -F':' '!/^root|toor|daemon|operator|bin|games|news|man|uucp|xten|nobody|ftp/{print $1}' /etc/passwd > /etc/aliases.allusers easier: awk -F':' '$3>100{print $1}' /etc/passwd > /etc/aliases.allusers Without alias: for i in `awk -F':' '$3>100{print $1}' /etc/passwd` do mail -s "Your Subject" $i <<% You can put you message en this space and can even use shell variables, executables, etc. % done Ed