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.
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.
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.
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
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
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
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.
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
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.
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?
>> 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.
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
==========================================================================
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
I vote for this one!
Then you'd want to exclude the :saved directory that MMDF puts in
/usr/spool/mail/
Funny how easy tasks are never easy...
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
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.