Link to home
Start Free TrialLog in
Avatar of coopa
coopa

asked on

Email all users ?

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...
Avatar of MFCRich
MFCRich

Set up an email alias for all users (man 5 alaiases)
Avatar of coopa

ASKER

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 ?
Avatar of coopa

ASKER

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

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.
Avatar of coopa

ASKER

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.

ASKER CERTIFIED SOLUTION
Avatar of samri
samri
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
#!/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.