Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 13 Apr 2003 15:28:42 +0100
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        Aslak Evang <nyogtha@flipp.net>
Cc:        questions@freebsd.org
Subject:   Re: mail to all users on a system (from root)
Message-ID:  <20030413142842.GB25131@happy-idiot-talk.infracaninophi>
In-Reply-To: <007a01c301b8$c329c290$3800000a@LAPDANCE>
References:  <007a01c301b8$c329c290$3800000a@LAPDANCE>

next in thread | previous in thread | raw e-mail | index | archive | help

--0lnxQi9hkpPO77W3
Content-Type: multipart/mixed; boundary="8GpibOaaTibBMecb"
Content-Disposition: inline


--8GpibOaaTibBMecb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Apr 13, 2003 at 02:32:35PM +0200, Aslak Evang wrote:
> I've searched for ways for root to email all users on a system. The only
> easy solution I found included making a shellscript and setting it as an
> alias for "everybody". Problem was that in the script you had to insert
> all your users manually.
> Does anybody know of other methods for sending announcements to all
> users on a system? Could have done it with MOTD but few of them actually
> log-in. Most just read mail.

Try the attached script which I just slung together.  To use, save the
script into a defined place on your HD, say /usr/local/sbin/everybody,
and then set up an alias:

    everybody:	"| /usr/local/sbin/everybody"

This script will resend the message to all users with an account on
the system -- I've assumed that real people have UIDs over 1000 and
system accounts have UIDs less than that.  Note that this is just a
quick hack and could be vastly improved --- certainly made much more
efficient --- with a little effort.  Only minimally tested: use very
cautiously.

In fact, you'ld probably be better off just modifying this script to
print out all of the $pw_name values one per line into a file, running
that occasionally and using the file as a mailing list via an include
in your aliases file.

	Cheers,

	Matthew

--=20
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK

--8GpibOaaTibBMecb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=everybody

#!/usr/bin/perl -w

use User::pwent qw{:FIELDS};

# Take an E-mail message on stdin and forward it to all users on the
# system.  Assumes that real users have UIDs >= 1000 and that system
# accounts do not (other than the nobody account, of course).

$0 =~ s@.*/@@;

MAIN:
{
    my $message;
    my $user;

    undef $/;    # Read in one go

    $message = <>;

    while ( getpwent() ) {
        next if ( $pw_uid < 1000 || $pw_name eq 'nobody' );

        open( SENDMAIL, "|/usr/sbin/sendmail -oi -oem $pw_name" )
          or do {
            warn "$0: Can't send to $pw_name -- $!\n";
            next;
          };
        print SENDMAIL $message;
        close SENDMAIL;
    }
}


--8GpibOaaTibBMecb--

--0lnxQi9hkpPO77W3
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (FreeBSD)

iD8DBQE+mXQadtESqEQa7a0RAv/NAJ9YmQXHVRs5dGk77uZLQrOUBipcjACbBrKL
ZzXDJiZ5wBAvk0pVbwXd6dM=
=VhXk
-----END PGP SIGNATURE-----

--0lnxQi9hkpPO77W3--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030413142842.GB25131>