Solved

Email all users ?

Posted on 2002-06-11
8
226 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

895 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

12 Experts available now in Live!

Get 1:1 Help Now