Solved

Email all users ?

Posted on 2002-06-11
8
225 Views
Last Modified: 2010-04-20
Is there an easy way to email all users on a Linux box?

I just want to be able to warn people if I'm going to shut it down etc etc...
0
Comment
Question by:coopa
8 Comments
 
LVL 4

Expert Comment

by:MFCRich
ID: 7069715
Set up an email alias for all users (man 5 alaiases)
0
 
LVL 2

Author Comment

by:coopa
ID: 7069727
Okay, makes sense...

Do I add this in the etc/mail/virtusertable file ?

I thought that was for one to one mapping... not sure how to do one to many... any ideas ?
0
 
LVL 2

Author Comment

by:coopa
ID: 7069736
This is what I meant by one to one mapping.

# CLIENT NAME ------------------------------------
chris@ourclient.co.uk                        chris
sales@ourclient.co.uk                        chris
gareth@ourclient.co.uk                       gareth

0
 
LVL 15

Expert Comment

by:samri
ID: 7069927
Alternately, you can extract all users from the /etc/passwd files and pipe it to a scripts to send the mail.

#!/bin/sh
userlist=`cat /etc/passwd | cut -d: -f1`
for username in $userlist; do
  echo Mailing to $username
  cat /path/to/msg.txt | /usr/lib/sendmail -v $username
done

---
and the msg.txt would be;
From: System Administrator
Subject: System Shutdown on 99/99/9999

We will be shutting down the server on the day
---

This should work.  And of course the scripts will mail to all user is passwd file.  You can modify the code by piping to a file first and remove all the system login-name(root,bin,etc.).

hope this helps.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Author Comment

by:coopa
ID: 7069974
That looks okay, but one thing... It returns stuff like

bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
gopher
ftp
nobody
vcsa
mailnull
rpm
ntp
rpc
xfs
 and more....

Won't it try to email these too ?
Oh yeah you mentioned that....   Okay... If you can give me an idea of how to write the script that removes the login names...

or preferably tell me how to do it using the virtusertable or equivalent, then the points are yours.

0
 
LVL 15

Accepted Solution

by:
samri earned 50 total points
ID: 7070372
coopa,

give the skeleton, you should be able to reconstruct the scripts to extract the mailaddress from the test version of virtusertable database.  Or if you are comfortable working with database (hash or dbm) you would be  looking at opening the hashes.  I would prefer to work on the plaintext version of virtusertable, since it's much simpler.

Assuming that your plaintext virtusertable is in /etc/mail

----
#!/bin/sh
userlist=`cat /etc/mail/virtusertable | cut -f1`

for username in $userlist; do
  echo Mailing to $username
  cat msg.txt | /usr/lib/sendmail -v $username
done
-----

I hope this should work.

Btw, back on the original example; Yes it will try to send the mail as well, but definetely it will bounce back.  Nobody will care anyway -  it's just a waste anyhow.  We can work on much advance (I'm not that good in shell programming), script to include the UID as well, and do not mail to those users that has UID< 500 (default smallest UID on RH).

0
 

Expert Comment

by:vage78
ID: 7835643
Hi
Lets say that I have already my userlist. What I must change in your code
#!/bin/sh
userlist = /etc/allusers
is it right this change?

where in allusers
george
chris
gkl
test
fotk
bbb
ccc
ksdj
0
 
LVL 15

Expert Comment

by:samri
ID: 7835949
#!/bin/sh
userlist=`cat /etc/allusers`

for username in $userlist; do
 echo Mailing to $username
 cat msg.txt | /usr/lib/sendmail -v $username
done
--

should work.

Aren't we support to start another thread?

cheers.

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now