Solved

Email all users ?

Posted on 2002-06-11
8
228 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
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 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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

789 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