[COLUG] Bash script trouble
Robert Grimm
robertgrimm at gmail.com
Wed Jan 30 14:12:01 EST 2008
I'm trying to make a script that will list all email address from
qmail and include all forwarding addresses in the .qmail-* files. I
want every address to be a single line. What I end up with is
something that looks like this:
name at domain.com
-> &targetaddress
If there is an address that forwards to two or more addresses, I get
each target address on a new line. I assume I need to use sed somehow,
but when I use it to replace the beginning character of lines that
begin with -> or & with a \b, I get those lines starting with ^M
rather than backspacing the contents to the end of the previous line.
What am I missing? Here is the script.
#!/bin/sh
#go to the domains directory
cd /home/vpopmail/domains
#remove the old alladdresses file
rm ~/alladdresses
#step through domains
for domain in $( ls -1 ); do
if [ -d $domain ] #if this is a valid domain
then
#list all real accounts, add @domain at the end,
leave out postmaster addresses
/home/vpopmail/bin/vuserinfo -D $domain -n | sed -e '/
postmaster/d' | sed -e "s/$/@$domain/" >> ~/alladdresses
#enter domain directory to get forwarders
cd $domain
#step through forwarders
for forward in $( ls -1 .qmail-* ); do
#convert filename into email address
echo -n $forward | cut -d - -f 2 | sed -e "s/
$/@$domain/" >> ~/alladdresses
#put target address after local address
echo -n "->" >> ~/alladdresses
cat $forward >> ~/alladdresses
done
fi
#go back to main domain directory
cd /home/vpopmail/domains
done
--
Robert Grimm
(614) 212-4625
http://www.datablitz.net
More information about the colug432
mailing list