SEX! or, how do I mail to a lot of unix users?

Dan KoGai dankg at tornado.Berkeley.EDU
Mon Jun 4 21:41:12 AEST 1990


In article <900531083002.30e0d06c at Csa2.LBL.Gov> thermal%solgel.hepnet at CSA2.LBL.GOV writes:
>I would like to be able to send a mail message to all the users on
>a unix machine.  Of course, I could do it the long way, that is,
>do a 'finger' or 'who', thus getting a list of all the users, and
>then sending a mail message to each, one at a time.  Is there a
>quicker way? (it seems to me there could be two or three different
>ways, such as setting up a mailing list, or some nifty command that
>will do this on one stroke of the finger).  Obviously, I'm not a
>unix guru or wizard, so make your explanation understandable, please.

	I advise aginst it:  1st of all it may clog /usr/spool/mail if
you batchmail something big.  2nd of all UNIX offers several other utilities
such as msgs to send messages to unspecific users.
	I say so because I'm an ex-con:  I did it once and my professor axed
me.  It's considered antisocial as long as UNIX has alternate ways.  But
batchmail appears anytime before election of student sanate and I'm pissed
to find those damn political campaigns on my already large mail file.
	However, since I am not a kind of person trying to secure things
by keeping people ignorant, I'll show you just one example.

	This works only when your system uses /etc/passwd, which is a lot
of cases but not necessarily true (most large sites use yp).
	On /etc/passwd, each users info is stored in each line, each field
delimited by ':'.  Login name appears 1st and that's the only thing you need.
so only thing it takes is:

Dana's prompt > mail `awk -F: '{print $1}' /etc/passwd`

	But this is hardly elegant, especially when you have too many accounts:
it may cause your mail header to overflow.  To avoid this, you can use
following csh script (Sorry, I'm berkeleynian and not used to sh):

#!/bin/csh -f
#foo
foreach address (`awk -F: '{print $1}' /etc/passwd`)
	mail $address < $1
end

	And invoke this script by "foo file-to-send".  Careful!  your
/etc/passwd might contain bogus uses and my example has no fool-proof feature.
to achieve it, just change awk script in there.
	If your site uses yp things are completely different but you still
got the idea: The only trick is how to get all user names.

	But I repeat:  Don't batchmail unless you have to:  Use msgs or other
utils.  If you have local newsgroups, post there!  Mail is supposed to be
for personal uses and I hate direct mails and stuffs.

----------------
____  __  __    + Dan The "ex-con" Man
    ||__||__|   + E-mail:	dankg at ocf.berkeley.edu
____| ______ 	+ Voice:	+1 415-549-6111
|     |__|__|	+ USnail:	1730 Laloma Berkeley, CA 94709 U.S.A
|___  |__|__|	+	
    |____|____	+ "What's the biggest U.S. export to Japan?" 	
  \_|    |      + "Bullshit.  It makes the best fertilizer for their rice"



More information about the Comp.unix.questions mailing list