Solved

Email all users ?

Posted on 2002-06-11
8
227 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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
 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

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 demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Fine Tune your automatic Updates for Ubuntu / Debian
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

770 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