thermal%solgel.hepnet@CSA2.LBL.GOV (05/31/90)
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. Thanks, Dana
jason@cs.odu.edu (Jason C Austin) (06/01/90)
In article <900531083002.30e0d06c@Csa2.LBL.Gov> thermal%solgel.hepnet@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.
->
-> Thanks, Dana
That would depend on what type of message that you want to
send. You can send an online to everyone currently logged in using
the ``wall'' command. If you're trying to send mail to everyone, one
way would be to build a list of users and have a shell script send
your mail to everyone. The following scripts would send mail to
everyone if you have your list of users in a file called user-list.
#!/bin/sh
users=`cat user-list`
for user in $users
do
echo "Mailing $user"
mail $user < message
done
Just a little warning about mass mailing like this. It tends
to put a large load on the mail handler, especially if you're mailing
a large file, so if you're mailing to a lot of people, you will
probably want to break them down into small groups.
--
Jason C. Austin
jason@cs.odu.edu
merlyn@iwarp.intel.com (Randal Schwartz) (06/01/90)
In article <JASON.90May31163242@aelle.cs.odu.edu>, jason@cs (Jason C Austin) writes: | #!/bin/sh | | users=`cat user-list` | | for user in $users | do | echo "Mailing $user" | mail $user < message | done Too many processes. If you want progress reporting, say: while read user do echo "Mailing $user" mail $user <message done <user-list If not, try: mail `cat user-list` <message Simple. Just another mail admin, -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/
fenske@iftccu.ca.boeing.com (Brian Fenske) (06/01/90)
I don't know if this command is available on all versions of UNIX but on our Sequent you can use the "users" command to produce a string of usernames. If joe, fred, bob and scooter are logged in, users produces joe fred bob scooter You could then just say mail `users` < message -- Brian Fenske Manufacturing Research & Development Boeing Commercial Airplanes 747-400 Integrated Functional Test System P.O. Box 3707, M/S 0P-37 (206) 342-5784 Seattle, WA 98124 ...uunet!bcstec!iftccu!fenske
murray@motto.UUCP (Murray S. Kucherawy) (06/02/90)
thermal%solgel.hepnet@CSA2.LBL.GOV.UUCP writes: >I would like to be able to send a mail message to all the users on >a unix machine... If you're lucky enough to have a system where each user has a directory someplace common (ie. /u/<username> for each user), then csh has a nice way of doing it: 1) Create the document you want to send 2) % foreach i (/u/*) ? mail -s "Memo for you" $i < source-file ? echo sent to $i ? end That oughta do it... =============================== Murray S. Kucherawy ========================== Motorola Canada, Ltd. Communications Division, Toronto [on work term] University of Waterloo, Ontario, Canada 2A Math (Comp Sci/Pure Math) Internet: murray@motto.UUCP (work) mskucherawy@watmath.UWaterloo.ca (UW) UUCP: uunet!utai!lsuc!motto!murray uunet!watmath!mskucherawy
ronald@atcmp.nl (Ronald Pikkert) (06/02/90)
From article <900531083002.30e0d06c@Csa2.LBL.Gov>, by thermal%solgel.hepnet@CSA2.LBL.GOV: > I would like to be able to send a mail message to all the users on ^^^ > a unix machine. Mailing to all user on your system, and not only to those currently on the system, could be done with a script like: mail `awk 'BEGIN {FS=":"} {print $1} ' < /etc/passwd` < tekstfile It takes ALL the names from the passwordfile and mailes each user. Take a textbook and study commandsubstitution if you're interested in really taking advantage of the capabilities of the (bourne)shell. The commandsubstitution mechanism is basicaly used if the output of a command is needed as an argument for another command. - Ronald Pikkert E-mail: ronald@atcmp.nl @ AT Computing b.v. Tel: 080 - 566880 Toernooiveld 6525 ED Nijmegen
dankg@tornado.Berkeley.EDU (Dan KoGai) (06/04/90)
In article <900531083002.30e0d06c@Csa2.LBL.Gov> thermal%solgel.hepnet@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@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"
jik@athena.mit.edu (Jonathan I. Kamens) (06/05/90)
In article <132@motto.UUCP>, murray@motto.UUCP (Murray S. Kucherawy) writes: |> 2) % foreach i (/u/*) |> ? mail -s "Memo for you" $i < source-file |> ? echo sent to $i |> ? end |> |> That oughta do it... No, actually, it shouldn't "oughta do it". If you do that, you're going to attempt to send mail to a lot of addresses of the form /u/username, something which is in all probability not going to work. Either you want to change the first line to foreach i (`cd /u; echo *`) or you want to change the second line to mail -s "Memo for you" $i:t < source-file In any case, this doesn't answer the [amended] question which was asked, since the original poster was talking about sending to everyone at a remote site. However, I don't like to see wrong information posted, even when the wrong information wouldn't answer the right question even if it were right :-). Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8495 Home: 617-782-0710
hovdesta@herald.usask.ca (Alfred Hovdestad) (06/05/90)
From article <900531083002.30e0d06c@Csa2.LBL.Gov>, by thermal%solgel.hepnet@CSA2.LBL.GOV: > 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. > > Thanks, Dana We use Ultrix here, but you can check your UNIX manuals for your system. In your .mailrc, you can define a user list for mailing a message to all on the list. The syntax is alias user_list name1 name2 name3 ... When mail is sent to the user_list, it is sent to all on the list. There is also a system wide alias file called /usr/lib/aliases that contains aliases that anyone on the system can use. +-----------------------------------------------------------------+ | Alfred Hovdestad | Internet: hovdestad@sask.usask.ca | | University of Saskatchewan | UUCP: hovdesta@dvinci.UUCP | | Canada | Voice: (306) 966-4828 | +-----------------------------------------------------------------+
leo@ehviea.ine.philips.nl (Leo de Wit) (06/05/90)
In article <1990May31.230138.14896@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes: |In article <JASON.90May31163242@aelle.cs.odu.edu>, jason@cs (Jason C Austin) writes: || #!/bin/sh || || users=`cat user-list` 1 fork, 1 exec. || || for user in $users || do || echo "Mailing $user" || mail $user < message || done | 2 forks & 2 execs for each user. | |Too many processes. If you want progress reporting, say: | |while read user |do | echo "Mailing $user" | mail $user <message |done <user-list | 1 fork for the redirected while, 2 forks & 2 execs for each user. Number of processes is the same (but you save an exec). Alternative: set -x # Let the shell do the progress report. for user in `cat user-list`; do mail $user <message; done (1 fork & 1 exec for cat, 1 fork & 1 exec for each user). Of course, for builtin echo's, not-forked redirected while loops the situation differs. Leo.
geoff@edm.uucp (Geoff Coleman) (06/07/90)
From article <804@ehviea.ine.philips.nl>, by leo@ehviea.ine.philips.nl (Leo de Wit): -> In article <1990May31.230138.14896@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes: -> |In article <JASON.90May31163242@aelle.cs.odu.edu>, jason@cs (Jason C Austin) writes: -> || #!/bin/sh -> || -> || users=`cat user-list` -> -> 1 fork, 1 exec. -> -> || -> || for user in $users -> || do -> || echo "Mailing $user" -> || mail $user < message -> || done -> | -> -> 2 forks & 2 execs for each user. -> -> | -> |Too many processes. If you want progress reporting, say: -> | -> |while read user -> |do -> | echo "Mailing $user" -> | mail $user <message -> |done <user-list -> | -> -> 1 fork for the redirected while, 2 forks & 2 execs for each user. -> -> Number of processes is the same (but you save an exec). -> Alternative: -> -> set -x # Let the shell do the progress report. -> for user in `cat user-list`; do mail $user <message; done -> -> (1 fork & 1 exec for cat, 1 fork & 1 exec for each user). -> -> Of course, for builtin echo's, not-forked redirected while loops the -> situation differs. -> -> Leo. And lets hope you don't work at an place where the password file has a few thousand entries. This will start up a ridiculous number of processes and bring the machine to its knees. This was a torture test we used to do to machines to see how they really performed. Geoff Coleman
todd@stiatl.UUCP (Todd Merriman) (06/07/90)
if test "$1" -a "$2" -a "$3" then if test -r $2 then size=`wc -l $2` echo "$size recipients..." i=1 while test $i -le $size do curmod=`sed -n ${i}p $2` echo "** mailing to $curmod $i/$size" i=`expr $i + 1` case `uname -m` in miti2) mailx -s "$1" $curmod < $3 ;; i386) # rmail broken in Interactive mail $curmod < $3 ;; esac done else echo "$2 missing!" exit 1 fi else echo 'mailist <subject> <destination list> <message file>' exit 1 fi exit 0 .MODULE mailist .LIBRARY util .TYPE command file .SYSTEM unix .AUTHOR Todd Merriman .LANGUAGE C .APPLICATION mail .DESCRIPTION Mail to a mailing list .ARGUMENTS mailist <subject> <destination list> <message file> .NARRATIVE The mailist utility calls the mail utility for each address in a mailing list. This utility allows the user to maintain mailing lists of virtually unlimited size (which is not possible using aliases with mailx). The mailing list is formatted such that each line contains one address. .RETURNS 0 if successful, 1 if the mailing list cannt be found .ENDOC END DOCUMENTATION
felixc@cbnewsj.att.com (felix.cabral) (06/08/90)
In article <1990Jun5.154401.8148@dvinci.usask.ca> hovdesta@herald.usask.ca writes: >From article <900531083002.30e0d06c@Csa2.LBL.Gov>, by thermal%solgel.hepnet@CSA2.LBL.GOV: >> Thanks, Dana Well, most people have given you suggestion for the second half of your ORed question. So lets talk about the first part, SEX! -- Felix Cabral {felixc@mtgzz.att.com} "Just give me a rad AT&T Bell Labs { att!mtgzz!felixc } wave, a rad board and Middletown,NJ { (201)957-5081 } a company sick day"