So at work we have some rarely used dial-in modems. The users are all configured locally on the router with the modem bank, so modemconfigfile contains strings like this:
!username sam password <removed>
Well, I needed to send a brief message to all of the modem users, so I needed a way to translate a few dozen of the lines above into something I could paste into the bcc: bar of my mua. Also a few of them were not using their real email usernames for the modem.
So given a handy local copy of the mail servers passwd file, here’s what I came up with:
grep username modemconfigfile |cut -d " " -f 2 | for USER in `cat`; do grep $USER passwd > /dev/null; echo $USER $?; done |grep 0 |cut -d " " -f 1 | sed firstname.lastname@example.org/g | tr '\n' ','
Which does indeed spit out a list of verified email addresses comma seperated, and ready to be pasted. It is still missing the real addresses of those users with different usernames, but there were only a few so I looked them up manually with the output of
grep username modemconfigfile |cut -d " " -f 2 | for USER in `cat`; do grep $USER passwd > /dev/null; echo $USER $?; done |grep -v 0
as a starting point.
Man I really need to learn perl or something. I couldn’t even fit that in an Identi.ca posting.
Update: DOH!, keen observers will have noticed that until this update, the above created output like user1.ourdomain.com, user2.ourdomain.com
Which of course are not email addresses. So s/./@/ and we’re back on track.
I guess that’s what I get for hours of DNS updating just previous. 😛