Several people have asked me before the easiest way to email all users on there mail server, particaly ISP's (Service announcements etc.)
There are several methods, including qpoppers built in bulletin feature, but my favourite is my method which I have show below.
To get it working, execute the following commands below as root:
1) awk -F: '$3 > 100 { print $1 }' /etc/passwd > /etc/mail/allusers
2) echo "allusers: :include:/etc/mail/allusers" >> /etc/aliases ; newaliases
3) echo "#\!/bin/sh" > /etc/periodic/daily/350.allusers
4) echo "awk -F: '$3 > 100 { print $1 }' /etc/passwd > /etc/mail/allusers" >> /etc/periodic/daily/350.allusers
5) chmod 0755 /etc/periodic/daily/350.allusers
What it does ===========
The first line parses /etc/passwd, and extracts a list of usernames with a UID greater than 100 and dumps them into the file /etc/mail/allusers.
The second entry then creates an alias called "allusers", which is based on the file /etc/mail/allusers, and runs newaliases to update the aliases database.
The next 3 lines create an entry in /etc/periodic, so that the list will be updated each morning at 2am.
You use this script by sending an email to "allusers@hostname".
This will then suck in the usernames from /etc/mail/allusers and email everyone on the system.
Have fun!
Sparc jamie@jamiesdomain.org.uk
|