Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bulk mailer from root

1 view
Skip to first unread message

Gary

unread,
Jun 22, 2001, 1:52:33 AM6/22/01
to
Does anyone have a mail script to send mail to all the users in the
passwd file on openserver? I would like to have it to send maintance
and update notices.
Gary

Ian Peattie

unread,
Jun 22, 2001, 5:09:53 AM6/22/01
to

One way to get a list of all the users in /etc/passwd is:

awk -F: '{print $1}' /etc/passwd

You can feed that into xargs to send them all mail. Note that not every
'user' is actually a person, so you might when to strip out the low uid
numbers.

If your users use pop3 to collect their mail, you might want to look at
the bulletin feature of popper as an alternative.

Ian.

--
Ian Peattie i...@john-richard.co.uk
Edinburgh, Scotland.

Bob Meyers

unread,
Jun 22, 2001, 2:13:04 PM6/22/01
to

"Gary" <ba...@wnclink.com> wrote in message
news:3B32DD21...@wnclink.com...

Its puzzle time!

How 'bout an on-the-fly solution?

for loginid in `cat /etc/passwd | grep -v ":\*:" | awk -F: ' print $1 '`
do
mail -s "News Flash" $loginid < message.txt
done

(this has not been tested)

Bob Meyers

unread,
Jun 22, 2001, 2:17:13 PM6/22/01
to
> > Does anyone have a mail script to send mail to all the users in the
> > passwd file on openserver? I would like to have it to send maintance
> > and update notices.
> > Gary
> >
>
> Its puzzle time!
>
> How 'bout an on-the-fly solution?
>
> for loginid in `cat /etc/passwd | grep -v ":\*:" | awk -F: ' print $1 '`
> do
> mail -s "News Flash" $loginid < message.txt
> done
>
> (this has not been tested)
>

make that grep command: grep ":x:" . I think that will get ordinary users
only.


Bob Meyers

unread,
Jun 22, 2001, 2:59:46 PM6/22/01
to
> make that grep command: grep ":x:" . I think that will get ordinary users
> only.

That isn't the right grep either. I need an eraser... or to stop posting. I
don't know how one can exclude system logins. On systems I do this by
creating and maintaining an alias such as a...@mydomain.com. Normal users
frequently use this to broadcast email too.


John DuBois

unread,
Jun 22, 2001, 6:51:55 PM6/22/01
to

In article <CAMY6.52$7d.2...@newshog.newsread.com>,
Bob Meyers <oregon...@yahoo.com> wrote:
+I don't know how one can exclude system logins.

A traditional way of doing this is to exclude any account whose login shell
does not appear in /etc/shells. For example:

mail `name -R -oU`

ftp://ftp.armory.com./pub/scripts/name


John
--
John DuBois jo...@sco.com KC6QKZ/AE
I wish to God these calculations had been executed by steam. - Charles Babbage

Brian K. White

unread,
Jun 22, 2001, 7:26:03 PM6/22/01
to

"Bob Meyers" <oregon...@yahoo.com> wrote in message
news:QULY6.45$7d.2...@newshog.newsread.com...

for something this simple, I'd use cut instead of awk. *has* to be faster
and lighter than awk I should think. and you get 3rd prize for this weeks
pointless use of cat :)

for loginid in `grep -v ":\*:" /etc/passwd | cut -d: -f1`


do
mail -s "News Flash" $loginid < message.txt
done

or, if I was going to use awk, then use it to do the whole job since awk is
a whole programming laguage and why fire it up just to run one single print
instruction? awk can do the whol ething, including the "for" loop, the grep,
the cut, and even the mail. In that case I'd actually make #!/bin/awk -f the
top line of the script and have nothing but awk commands in it. But it's not
necessary in this case. the above shell example is fine.

the reason you do often see that single instruction awk command is because
it's the easiest way to get say, the 3rd field in a string regardless of how
many spaces and tabs are seperating the 3rd field from the 2nd and the 4th.
but you are not using that feature at all in this case, and so it is
wasteful.

--
Brian K. White -- br...@aljex.com -- http://www.aljex.com/bkw/
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro BBx Linux SCO Prosper/FACTS AutoCAD #callahans Satriani


Bob Meyers

unread,
Jun 22, 2001, 8:03:28 PM6/22/01
to

"Brian K. White" <br...@aljex.com> wrote in message
news:fuQY6.296151$K5.31...@news1.rdc1.nj.home.com...

> for something this simple, I'd use cut instead of awk. *has* to be faster
> and lighter than awk I should think. and you get 3rd prize for this weeks
> pointless use of cat :)

Good point, I often just cat into a pipe, bad habit. But then if you are
learning shell scripts (or writing them) CATing something as important as
/etc/passwd is much safer than using it as an argument to a program,
wouldn't it (spare the root login lecture:) ?

> or, if I was going to use awk, then use it to do the whole job since awk
is
> a whole programming laguage

I am sure of this

> the reason you do often see that single instruction awk command is because
> it's the easiest way to get say, the 3rd field in a string

Or, as in my case, it is all that remains on the outer fringes of my memory
and awk skill.

One more shot, this should eliminate most SCO standard system id's, someone
can volunteer to rewrite it in awk, or something else, but I want to see it
as simple and short, and as elementary :)

for loginid in `cat /etc/passwd | awk -F: '{ print $1 }'`
do
if echo "root|daemon|bin|sys|adm|uucp|nuucp|auth|\
asg|cron|sysinfo|dos|mmdf|network|backup|\
nouser|listen|lp|audit" | grep -v $loginid > /dev/null
then
mail -s "News flash" $loginid < message.txt
fi
done


Brian K. White

unread,
Jun 23, 2001, 7:19:19 AM6/23/01
to

"Bob Meyers" <oregon...@yahoo.com> wrote in message
news:k1RY6.18$5d.1...@newshog.newsread.com...

>
> "Brian K. White" <br...@aljex.com> wrote in message
> news:fuQY6.296151$K5.31...@news1.rdc1.nj.home.com...
> > for something this simple, I'd use cut instead of awk. *has* to be
faster
> > and lighter than awk I should think. and you get 3rd prize for this
weeks
> > pointless use of cat :)
>
> Good point, I often just cat into a pipe, bad habit. But then if you are
> learning shell scripts (or writing them) CATing something as important as
> /etc/passwd is much safer than using it as an argument to a program,
> wouldn't it (spare the root login lecture:) ?

quite. forgot about that actually.
I've even catted files into lp on occasion on a strange system for prcisely
this reason.

.oO(I know in both linux and sco lp/lpr, there are lp command-line switches
that mean "delete file after printing". Do I know without a doubt know for a
fact know know know that this lp does not do that by default unless you
specifically tell it not to?)

> One more shot, this should eliminate most SCO standard system id's,
someone
> can volunteer to rewrite it in awk, or something else, but I want to see
it
> as simple and short, and as elementary :)
>
> for loginid in `cat /etc/passwd | awk -F: '{ print $1 }'`
> do
> if echo "root|daemon|bin|sys|adm|uucp|nuucp|auth|\
> asg|cron|sysinfo|dos|mmdf|network|backup|\
> nouser|listen|lp|audit" | grep -v $loginid > /dev/null
> then
> mail -s "News flash" $loginid < message.txt
> fi
> done

I like the idea from the other post where you go by the login shell.
That way properly handles, for exampple, PPP logins that are login-capable,
but never the less, not real users.

Bill Vermillion

unread,
Jun 22, 2001, 4:25:29 PM6/22/01
to
In article <CAMY6.52$7d.2...@newshog.newsread.com>,
Bob Meyers <oregon...@yahoo.com> wrote:

You could check the UID when you parse the password file and only
take users above 200, or whatever the lowest user ID is on your
system.


--
Bill Vermillion - bv @ wjv . com

John DuBois

unread,
Jun 24, 2001, 8:18:42 PM6/24/01
to

In article <XW_Y6.297448$K5.32...@news1.rdc1.nj.home.com>,
Brian K. White <br...@aljex.com> wrote:
+(I know in both linux and sco lp/lpr, there are lp command-line switches
+that mean "delete file after printing". Do I know without a doubt know for a
+fact know know know that this lp does not do that by default unless you
+specifically tell it not to?)

If you do 'lp < filename', lp never sees filename and gets a read-only file
descriptor for it, and so has no means to remove/truncate it.

Robert Carnegie

unread,
Jun 25, 2001, 5:48:36 AM6/25/01
to
"Bob Meyers" <oregon...@yahoo.com> wrote in message news:<QULY6.45$7d.2...@newshog.newsread.com>...

In the past I've seen MMDF mail fail when I try to use the command too
often - but maybe that's Nature's way of telling us not to use MMDF?
I empirically determined that putting a few seconds' delay "sleep 3"
after each invocation of "mail ..." was reasonably safe. That might be
a few server upgrades ago now...

Elsewhere in this thread, system accounts were being excluded from e-mail
using one "grep" per candidate loginid which might/might not be a system
account. The objection that grep may be computationally expensive when
executed once for each user possibly doesn't apply if the "mail" command
itself is more so. Nevertheless, I'll express a preference for constructing
a list of addressees and then filtering it with "grep" just once.
For that matter, could "mail" be invoked just once, too, or would that
involve an excessively long command line?

Bill Vermillion

unread,
Jun 25, 2001, 8:48:52 AM6/25/01
to
In article <f3f18bc0.01062...@posting.google.com>,

Robert Carnegie <rja.ca...@excite.com> wrote:
>"Bob Meyers" <oregon...@yahoo.com> wrote in message news:<QULY6.45$7d.2...@newshog.newsread.com>...
>> "Gary" <ba...@wnclink.com> wrote in message
>> news:3B32DD21...@wnclink.com...
>> > Does anyone have a mail script to send mail to all the users in the
>> > passwd file on openserver? I would like to have it to send maintance
>> > and update notices.

>> Its puzzle time!

>> How 'bout an on-the-fly solution?

>> for loginid in `cat /etc/passwd | grep -v ":\*:" | awk -F: ' print $1 '`
>> do
>> mail -s "News Flash" $loginid < message.txt
>> done

>> (this has not been tested)

>In the past I've seen MMDF mail fail when I try to use the command too
>often - but maybe that's Nature's way of telling us not to use MMDF?
>I empirically determined that putting a few seconds' delay "sleep 3"
>after each invocation of "mail ..." was reasonably safe. That might be
>a few server upgrades ago now...

Well the proper solution, at least from my point of view which
often times differes with others, is that if you are going to scan
the password file for name, then you >build a list< of names,
and submit that list to the mailer.

If this is something you do often, you could have a weekly/nightly
routine that scans the password file, and contstructs and builds a file
which then is used to construct a new aliases file. That way
an alias of 'all' for example, is always available.

Tom Parsons

unread,
Jun 27, 2001, 10:35:10 AM6/27/01
to sco...@xenitec.on.ca
Bill Vermillion enscribed:

There is no reliable way to parse the password file and obtain a list
of active users.
Administrative uid's do not have to be below 200, users added by
3rd party applications are often added above 200
Removing "old" users from the password file is not necessarily a good
idea and with some levels of security, impossible.
Retired users still stay in the password file

The sysadmin has to enter into the process in some manner. Probably the
simplest would be to remove the mail box when a user is no longer allowed
access to the system but nothing does that automagically. Or, you could
wrap the account manager with a shell script that maintains a mailing
list alias.

--tom
==========================================================================
Tom Parsons t...@tegan.com
==========================================================================

Bob Stockler

unread,
Jun 27, 2001, 12:31:53 PM6/27/01
to SCO Miscellaneous

It gets ALL users.

How about:

cd /usr/spool/mail
for user in *
do mail -s "News Flash" $user < message.txt
done


--
Bob Stockler - b...@trebor.iglou.com

Bob Meyers

unread,
Jun 28, 2001, 11:31:21 AM6/28/01
to

"Bob Stockler" <b...@trebor.iglou.com> wrote in message
news:2001062712...@trebor.iglou.com...

>
> cd /usr/spool/mail
> for user in *
> do mail -s "News Flash" $user < message.txt
> done
>

I vote for this one!


Ian Peattie

unread,
Jun 28, 2001, 11:37:33 AM6/28/01
to

Then you'd want to exclude the :saved directory that MMDF puts in
/usr/spool/mail/

Funny how easy tasks are never easy...

Jean-Pierre Radley

unread,
Jun 28, 2001, 7:43:00 PM6/28/01
to ScoMisc [c.u.s.m]
Bob Meyers propounded (on Thu, Jun 28, 2001 at 03:31:21PM +0000):

Maybe.

Some MUAs leave zero-length mailboxes in place. I use mutt and configure
it to delete them, so Bob's scheme would not catch everyone.


--
JP

Bob Stockler

unread,
Jun 28, 2001, 8:58:18 PM6/28/01
to SCO Miscellaneous
On Thu, Jun 28, 2001 at 03:37:33PM +0000, Ian Peattie wrote:
| In article <d5I_6.974$5d.4...@newshog.newsread.com>, "Bob Meyers" <oregon...@yahoo.com> wrote:
| >
| >"Bob Stockler" <b...@trebor.iglou.com> wrote in message
| >news:2001062712...@trebor.iglou.com...
| >>
| >> cd /usr/spool/mail
| >> for user in *
| >> do mail -s "News Flash" $user < message.txt
| >> done
| >>
| >
| >I vote for this one!

Thanks for the vote.

| Then you'd want to exclude the :saved directory that MMDF puts in
| /usr/spool/mail/

I'd swear I tried it before, and (to my surprise) ":saved" didn't
show up in the expansion of the star, so I omitted the test to
exclude it. Trying it again, it does, so:

cd /usr/spool/mail
for user in *

do [ "$user" = ":saved" ] && continue


mail -s "News Flash" $user < message.txt
done

| Funny how easy tasks are never easy...

But not much more difficult sometimes.

Bob

PS - This still ignores considering users that are retired
if their mailboxes aren't retired with them.

Bob Meyers

unread,
Jun 29, 2001, 12:27:15 AM6/29/01
to

"Bob Stockler" <b...@trebor.iglou.com> wrote in message > | >I vote for this

one!
>
> Thanks for the vote.
>
> | Then you'd want to exclude the :saved directory that MMDF puts in
> | /usr/spool/mail/
>
Well after JP's comment, I retract my vote. I think the only thing one can
do is base it on etc/shells, as John Dubois pointed out.

0 new messages