Created
November 15, 2014 10:34
-
-
Save jagland/321558dace4e3ead24f4 to your computer and use it in GitHub Desktop.
Generate Address List from Aliases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Generate Address List from Aliases and drop an e-mail with an txt attachment | |
# Useful for importing to other mail systems that require a list of valid addresses | |
# for a particular domain. | |
if [ "$1" == "" ] | |
then | |
echo "Give me your email address..." | |
else | |
TMPFILE=`mktemp` | |
TMPFILE2=`mktemp` | |
DOM="newdomain" | |
cat /etc/aliases | grep -v '^$' | grep -v '^;' | awk -v d=$DOM -F\: '{ print $1"@"d }' > $TMPFILE | |
dos2unix -q $TMPFILE | |
mv $TMPFILE /tmp/$DOM.txt | |
echo "Total number of entries.." >>$TMPFILE2 | |
wc -l /tmp/$DOM.txt | awk '{print $1}' >>$TMPFILE2 | |
mailx -s $DOM" address list" -a /tmp/$DOM.txt $1 <$TMPFILE2 | |
rm /tmp/$DOM.txt | |
cat $TMPFILE2 | |
rm $TMPFILE2 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment