Solved

Email all users ?

Posted on 2002-06-11
8
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Back Up Your Microsoft Windows Server®

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

735 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