Finding all e-mail addresses in files on server. - Unix

This is a discussion on Finding all e-mail addresses in files on server. - Unix ; Looking for advice and/or examples on how to audit a server to find all possible e-mail addresses listed in files. Need to verify and possibly consolidate addresses for server monitoring and administration. What I have been doing is greping thru ...

+ Reply to Thread
Results 1 to 17 of 17

Thread: Finding all e-mail addresses in files on server.

  1. Finding all e-mail addresses in files on server.

    Looking for advice and/or examples on how to audit a server to find all
    possible e-mail addresses listed in files. Need to verify and possibly
    consolidate addresses for server monitoring and administration. What I
    have been doing is greping thru the filesystem and checking for
    matches to entries in /etc/mail/aliases, /etc/password and any lines
    containing "mail" (case insensitive) or "@" in crontabs, and scripts.

    What I would like to do is create an exclude list of certain
    directories. Then go through the remaining dirs. and extract mail
    addresses and print them to a file with the filename. This would be run
    on a production systems during off hours but still needs to be "nice"
    to system resources. I want to automate this as much as possible. So
    that we can periodically do an audit of all our systems.

    Has anybody done anything like this previously? Any pointers or advice
    greatly appreciated.


  2. Re: Finding all e-mail addresses in files on server.

    On comp.unix.shell, in
    <1112576768.533990.100930@z14g2000cwz.googlegroups. com>,
    "ifoutch@gmail.com" wrote:


    > Looking for advice and/or examples on how to audit a server
    > to find all possible e-mail addresses listed in files. Need
    > to verify and possibly consolidate addresses for server
    > monitoring and administration. What I have been doing is
    > greping thru the filesystem and checking for matches to entries
    > in /etc/mail/aliases, /etc/password and any lines containing
    > "mail" (case insensitive) or "@" in crontabs, and scripts.
    >
    > What I would like to do is create an exclude list of certain
    > directories. Then go through the remaining dirs. and extract
    > mail addresses and print them to a file with the filename. This
    > would be run on a production systems during off hours but still
    > needs to be "nice" to system resources. I want to automate this
    > as much as possible. So that we can periodically do an audit of
    > all our systems.
    >
    > Has anybody done anything like this previously? Any pointers or
    > advice greatly appreciated.
    >


    I ran a search at http://groups.google.com/advanced_group_search

    on ifoutch@gmail.com

    This is the only post ever made on a Usenet textgroup under that
    alias.

    If you feel the need to hide, and want to extract email addresses
    from a bunch of dirs, then you are probably a spammer. Or a
    wannabee spammer.

    Here's the script I wrote that does everything you want. All the
    numbers and letters have been converted to Os with my handy
    vi macro.

    I learned some good things putting it together. Thanks.

    And **** off.


    (OOO OOO OOO OOOO)

    #!/OOO/OOOO

    OOO _OOOO OO $(OOOO / -OOOO "/OOO" -O -OOOO "/OOOO" -O \
    -OOOO "/OOOO"\) -OOOOO -O -OOOO O -OOOOO)

    do

    OOO -O 'O/\(.*\)\([O-OO-OO-O_.+-]+@[O-OO-OO-O_.+-\
    ]+\.[O-OO-OO-O]+\)\(.*\)/\O/O' $_OOOO >> OOOOOOOOOO

    OOOO

    #OO OOOO OO OOO OOO OOOO OOOOO OOO OOO OOOO \
    #(OOO,OOOO...) OO OOO OOOO OOOOOO.

    OOOO O

    AC



  3. Re: Finding all e-mail addresses in files on server.

    I have posted as ifoutch@yahoo.com and possibly even as
    ifoutch@hotmail.com. I am a newbie SA trying to find my way in my new
    job.

    The reason for needing to extract mail addresses is that different
    "admins" have created scripts that functioned as some sort of monitor
    and notification system. The problem is that the notification may not
    be going to an address that will be of any use anymore. So I am trying
    to track these down and either retire the scripts or change the address
    to something appropriate.

    -- Ian Foutch
    P.S. Nice manners you have when addressing someone you know nothing
    about!


  4. Re: Finding all e-mail addresses in files on server.

    On comp.unix.shell, in
    , "Alan
    Connor" wrote:


    > On comp.unix.shell, in
    ><1112576768.533990.100930@z14g2000cwz.googlegroups. com>,
    >"ifoutch@gmail.com" wrote:
    >
    >
    >> Looking for advice and/or examples on how to audit a server
    >> to find all possible e-mail addresses listed in files. Need
    >> to verify and possibly consolidate addresses for server
    >> monitoring and administration. What I have been doing is
    >> greping thru the filesystem and checking for matches to
    >> entries in /etc/mail/aliases, /etc/password and any lines
    >> containing "mail" (case insensitive) or "@" in crontabs, and
    >> scripts.
    >>
    >> What I would like to do is create an exclude list of certain
    >> directories. Then go through the remaining dirs. and
    >> extract mail addresses and print them to a file with the
    >> filename. This would be run on a production systems during
    >> off hours but still needs to be "nice" to system resources. I
    >> want to automate this as much as possible. So that we can
    >> periodically do an audit of all our systems.
    >>
    >> Has anybody done anything like this previously? Any pointers
    >> or advice greatly appreciated.

    >
    >
    > I ran a search at
    > http://groups.google.com/advanced_group_search
    >
    > on ifoutch@gmail.com
    >
    > This is the only post ever made on a Usenet textgroup under
    > that alias.
    >
    > If you feel the need to hide, and want to extract email
    > addresses from a bunch of dirs, then you are probably a
    > spammer. Or a wannabee spammer.
    >
    > Here's the script I wrote that does everything you want. All
    > the numbers and letters have been converted to Os with my handy
    > vi macro.
    >
    > I learned some good things putting it together. Thanks.
    >
    > And **** off.
    >
    >
    > (OOO OOO OOO OOOO)
    >
    > #!/OOO/OOOO
    >
    > OOO _OOOO OO $(OOOO / -OOOO "/OOO" -O -OOOO "/OOOO" -O \
    > -OOOO "/OOOO"\) -OOOOO -O -OOOO O -OOOOO)
    >
    > OO
    >
    > OOO -O 'O/\(.*\)\([O-OO-OO-O_.+-]+@[O-OO-OO-O_.+-\
    > ]+\.[O-OO-OO-O]+\)\(.*\)/\O/O' $_OOOO >> OOOOOOOOOO
    >
    > OOOO
    >
    > #OO OOOO OO OOO OOO OOOO OOOOO OOO OOO OOOO \
    > #(OOO,OOOO...) OO OOO OOOO OOOOOO.
    >
    > OOOO O
    >
    > AC
    >
    >


    Oops! Made a booboo. Used eregexes where they won't work.

    #!/OOO/OOOO

    OOO _OOOO OO $(OOOO / -OOOO "/OOO" -O -OOOO "/OOOO" -O \
    -OOOO "/OOOO"\) -OOOOO -O -OOOO O -OOOOO)

    OO

    OOO -O 'O/\(.*\)\([O-OO-OO-O_.+-]\{O,\}@[O-OO-OO-O_.+-\
    ]\{O,\}\.[O-OO-OO-O]\{O,\}\)\(.*\)/\O/O' $_OOOO >> OOOOOOOOOO

    OOOO

    #OO OOOO OO OOO OOO OOOO OOOOO OOO OOO OOOO \
    #(OOO,OOOO...) OO OOO OOOO OOOOOO.

    OOOO O

    There. Perfect! Just fill in the dirs you don't want searched
    and run the script and it will produce a lovely list of
    email addresses, one per line, no garbage.

    Hope this helps,

    AC


  5. Re: Finding all e-mail addresses in files on server.

    On comp.unix.shell, in
    <1112582256.601080.108550@z14g2000cwz.googlegroups. com>,
    "ifoutch@gmail.com" wrote:


    > I have posted as ifoutch@yahoo.com and possibly even as
    > ifoutch@hotmail.com. I am a newbie SA trying to find my way in
    > my new job.
    >
    > The reason for needing to extract mail addresses is that
    > different "admins" have created scripts that functioned as
    > some sort of monitor and notification system. The problem is
    > that the notification may not be going to an address that will
    > be of any use anymore. So I am trying to track these down and
    > either retire the scripts or change the address to something
    > appropriate.
    >
    > -- Ian Foutch P.S. Nice manners you have when addressing
    > someone you know nothing about!
    >


    That's the problem, fool: I don't know anything about you.

    Except that you want to extract email addresses from a bunch
    of files. Which is what spammers do.

    Like whether you tell the truth or not on the Usenet.

    And I can't search your posting history to find out, and
    have no idea whether you have anything to do with any
    formal organization at all.

    What company do you work for? What's your name so that I
    can ask them if you work there?

    Are you ashamed of them? Is that why you don't use the name?

    What's wrong with the RCN Corporation in Princeton N.J.?

    Do they know that you are using their computers or connection?

    What I do know about you is that you are hiding by changing
    your alias regularly and are evasive about even that.

    Like I said: **** Off.

    AC


  6. Re: Finding all e-mail addresses in files on server.

    On comp.unix.shell, in
    <1112576768.533990.100930@z14g2000cwz.googlegroups. com>,
    "ifoutch@gmail.com" wrote:

    I just sent this whole thread, including all headers, to
    noc@rcn.com

    You had better be legit.

    If you are, I'm not going to apologize because you should have
    said what company you worked for and used your real name and
    work email address.

    I just can't figure out why _I_ would know how to do what you
    want, almost off the top of my head, being only an amateur linux
    user, while you, a "sysadmin", has to ask someone how to do it.

    Makes no sense.

    I suspect that you have gained the root password at your
    workplace (or someone else's workplace) illicitly, and are doing
    some very un-authorized snooping.

    You sure ran like a rabbit when you found out I knew where you
    were posting from. Or _through_.

    Kind of late for someone in NJ to be working. Especially on
    a Sunday night....

    Are you a windoze cracker that finds himself lost on a
    nix system?

    A janitor there?

    AC



  7. Re: Finding all e-mail addresses in files on server.

    On Mon, 04 Apr 2005 03:48:18 GMT, Alan Connor wrote:
    >
    > If you are, I'm not going to apologize because you should have
    > said what company you worked for and used your real name and
    > work email address.


    There is no good reason to do so.
    Far too many idiots out in Usenet land.

    > I just can't figure out why _I_ would know how to do what you
    > want, almost off the top of my head, being only an amateur linux
    > user, while you, a "sysadmin", has to ask someone how to do it.
    >
    > Makes no sense.


    Unless you are out in the real world. Maybe the senior sysadmin was
    layed off and the second team was thrown into the breach. Or
    management decided to outsource the IT department and the new people
    are having to scramble to understand what they signed up for.

    > I suspect that you have gained the root password at your
    > workplace (or someone else's workplace) illicitly, and are doing
    > some very un-authorized snooping.


    Well if he a totally clueless as you indicate and has managed to
    gained root access, him searching for email addresses
    are the least of their worries.

    > Kind of late for someone in NJ to be working. Especially on
    > a Sunday night....


    See, you realy are totaly clueless.
    When do you think sysadmins get to do whatever they like on production
    systems. It sure as h*11 is not 9am Monday morning.

    Friday is also a good massive layoff day to allow support people to disable
    accouts, change ownership of file, copying employee files into
    management directories, ...... Depending on the size of the layoff
    cleanup work can still be going on come Monday morning.


  8. Re: Finding all e-mail addresses in files on server.

    On Mon, 04 Apr 2005 at 02:37 GMT, ifoutch@gmail.com wrote:
    > I have posted as ifoutch@yahoo.com and possibly even as
    > ifoutch@hotmail.com. I am a newbie SA trying to find my way in my new
    > job.
    >
    > The reason for needing to extract mail addresses is that different
    > "admins" have created scripts that functioned as some sort of monitor
    > and notification system. The problem is that the notification may not
    > be going to an address that will be of any use anymore. So I am trying
    > to track these down and either retire the scripts or change the address
    > to something appropriate.
    >
    > -- Ian Foutch
    > P.S. Nice manners you have when addressing someone you know nothing
    > about!


    Don't bother responding to our resident kook. Most people here have
    killfiled him.

    --
    Chris F.A. Johnson http://cfaj.freeshell.org/shell
    ================================================== =================
    Everything in moderation -- including moderation


  9. Re: Finding all e-mail addresses in files on server.

    Thank you BT and CJ... Actually Chris has offered extremely useful
    solutions to a few of my previous posts in the past and I've much
    appreciated it. I even pre-ordered his book, still waiting

    I ended up an SA because I showed some abilties with my shell scripting
    while working as a NOC operator. Unfortunately without any previous
    experience, schooling or training. The job is not as easy I would like.
    Every task I get I have to learn it as I go and much of that ends up
    during the evening on my own time.

    This task sounds easy enough except that it gets messy really quick and
    I dislike messy scripts. I can figure out how to use grep, find, sed,
    xargs, awk, cut and whatever else need. What I am looking for is
    pointers in the "best" way to do this and any advice on what I might
    likely overlook.

    I keep telling myself i will join a LUG in my home town (not NJ by the
    way!) so that I might find a couple mentors/peers to work with. Looks
    like that has become a high priority todo. People have much nicer
    manners when they are face to face and they need to be concerned about
    the condition of such after an exchange.

    -- Ian


  10. Re: Finding all e-mail addresses in files on server.

    On 3 Apr 2005 22:29:18 -0700, ifoutch@gmail.com wrote:
    > Thank you BT and CJ... Actually Chris has offered extremely useful
    > solutions to a few of my previous posts in the past and I've much
    > appreciated it.


    Yes Chris does help alot of people.

    > I ended up an SA because I showed some abilties with my shell scripting
    > while working as a NOC operator. Unfortunately without any previous
    > experience, schooling or training. The job is not as easy I would like.


    Been there done that.

    > Every task I get I have to learn it as I go and much of that ends up
    > during the evening on my own time.


    Yes, I have take home lots of work or dialed in after getting home.


    > This task sounds easy enough except that it gets messy really quick and
    > I dislike messy scripts.


    I find pushing the acutal work as far down into a subroutine/funmction helps on
    messy stuff.

    > I can figure out how to use grep, find, sed, xargs, awk, cut and
    > whatever else need. What I am looking for is pointers in the "best"
    > way to do this and any advice on what I might likely overlook.


    From what you have described, I would have created the list of files
    to munge. Look at the lines to be munged, and see if a small
    function/subroutine can make the changes.

    Then use a loop to read the list to process files into a tmp workspace
    and check the results. If they are valid, backup the production
    scripts into a fallback directory, and install the new ones. If
    production throws up, run the fallback script to copy fallback scripts
    back into production.

    No way would I run a script to mass update a bunch of scripts on a
    production box with my fingers crossed.

    > People have much nicer manners when they are face to face and they
    > need to be concerned about the condition of such after an exchange.


    Never let anyone's post bother you. Watch them for awhile to see if
    they are worth your time, kill file them if they are of no use.

    Anytime I run into a mess/problem like yours, I'll put the variable
    element into a config file, source it in a script, and use a variable in the
    scripts.

    As an application programmer, I put lots of tests in my scripts to
    verify nodes I need, database listners, mount points
    needed by my app were realy there. When a check failed, it would
    create a message file, and call the nofity funcition with who to
    contact, subject, filename of problem description.
    Example email variable names: $dba, $sysops, $crash, $coder, $mgr,
    $sysadmin, $fyi...

    Notify function would then add in node, time, script name, application
    and call mailx -s "$2" $1 < $3

    That reduced the O dark thirty calls to me when my production scripts
    aborted because of external failures.
    Also allowed me to run the scripts on the development and test
    bed systems without bothering the production group by changing names
    in my config file.

  11. Re: Finding all e-mail addresses in files on server.

    In comp.unix.shell ifoutch@gmail.com wrote:
    > Looking for advice and/or examples on how to audit a server to find all
    > possible e-mail addresses listed in files. Need to verify and possibly
    > consolidate addresses for server monitoring and administration. What I
    > have been doing is greping thru the filesystem and checking for
    > matches to entries in /etc/mail/aliases, /etc/password and any lines
    > containing "mail" (case insensitive) or "@" in crontabs, and scripts.
    >
    > What I would like to do is create an exclude list of certain
    > directories. Then go through the remaining dirs. and extract mail
    > addresses and print them to a file with the filename.


    You have received flames and encouragement, but no answers.

    Maybe you can use a find command, something like:

    find / -path /first/excluded -prune -o -path /second/excluded -prune \
    -o -type f -exec egrep -li '([^ @]+@[^ @]+|mail)' {} \;

    Yours,
    Laurenz Albe

  12. Re: Finding all e-mail addresses in files on server.

    On 2005-04-04, Alan Connor wrote:
    > On comp.unix.shell, in
    ><1112576768.533990.100930@z14g2000cwz.googlegroups. com>,
    > "ifoutch@gmail.com" wrote:
    >
    >
    >> Looking for advice and/or examples on how to audit a server
    >> to find all possible e-mail addresses listed in files. Need
    >> to verify and possibly consolidate addresses for server
    >> monitoring and administration. What I have been doing is
    >> greping thru the filesystem and checking for matches to entries
    >> in /etc/mail/aliases, /etc/password and any lines containing
    >> "mail" (case insensitive) or "@" in crontabs, and scripts.
    >>
    >> What I would like to do is create an exclude list of certain
    >> directories. Then go through the remaining dirs. and extract
    >> mail addresses and print them to a file with the filename. This
    >> would be run on a production systems during off hours but still
    >> needs to be "nice" to system resources. I want to automate this
    >> as much as possible. So that we can periodically do an audit of
    >> all our systems.
    >>
    >> Has anybody done anything like this previously? Any pointers or
    >> advice greatly appreciated.
    >>

    >
    > I ran a search at http://groups.google.com/advanced_group_search
    >
    > on ifoutch@gmail.com
    >
    > This is the only post ever made on a Usenet textgroup under that
    > alias.
    >
    > If you feel the need to hide, and want to extract email addresses
    > from a bunch of dirs, then you are probably a spammer. Or a
    > wannabee spammer.
    >
    > Here's the script I wrote that does everything you want. All the
    > numbers and letters have been converted to Os with my handy
    > vi macro.
    >
    > I learned some good things putting it together. Thanks.
    >
    > And **** off.
    >
    >
    > (OOO OOO OOO OOOO)
    >
    > #!/OOO/OOOO
    >
    > OOO _OOOO OO $(OOOO / -OOOO "/OOO" -O -OOOO "/OOOO" -O \
    > -OOOO "/OOOO"\) -OOOOO -O -OOOO O -OOOOO)
    >
    > do
    >
    > OOO -O 'O/\(.*\)\([O-OO-OO-O_.+-]+@[O-OO-OO-O_.+-\
    > ]+\.[O-OO-OO-O]+\)\(.*\)/\O/O' $_OOOO >> OOOOOOOOOO
    >
    > OOOO
    >
    > #OO OOOO OO OOO OOO OOOO OOOOO OOO OOO OOOO \
    > #(OOO,OOOO...) OO OOO OOOO OOOOOO.
    >
    > OOOO O
    >
    > AC
    >


    LOL I like that hahahahaha.

    --
    ( When in doubt, use brute force. -- Ken Thompson 1998 )

  13. Re: Finding all e-mail addresses in files on server.

    On 2005-04-04, Bit Twister wrote:
    > On 3 Apr 2005 22:29:18 -0700, ifoutch@gmail.com wrote:
    >> Thank you BT and CJ... Actually Chris has offered extremely useful
    >> solutions to a few of my previous posts in the past and I've much
    >> appreciated it.

    >
    > Yes Chris does help alot of people.
    >
    >> I ended up an SA because I showed some abilties with my shell scripting
    >> while working as a NOC operator. Unfortunately without any previous
    >> experience, schooling or training. The job is not as easy I would like.

    >
    > Been there done that.
    >
    >> Every task I get I have to learn it as I go and much of that ends up
    >> during the evening on my own time.

    >
    > Yes, I have take home lots of work or dialed in after getting home.
    >
    >
    >> This task sounds easy enough except that it gets messy really quick and
    >> I dislike messy scripts.

    >
    > I find pushing the acutal work as far down into a subroutine/funmction helps on
    > messy stuff.
    >
    >> I can figure out how to use grep, find, sed, xargs, awk, cut and
    >> whatever else need. What I am looking for is pointers in the "best"
    >> way to do this and any advice on what I might likely overlook.

    >
    > From what you have described, I would have created the list of files
    > to munge. Look at the lines to be munged, and see if a small
    > function/subroutine can make the changes.
    >
    > Then use a loop to read the list to process files into a tmp workspace
    > and check the results. If they are valid, backup the production
    > scripts into a fallback directory, and install the new ones. If
    > production throws up, run the fallback script to copy fallback scripts
    > back into production.
    >
    > No way would I run a script to mass update a bunch of scripts on a
    > production box with my fingers crossed.
    >
    >> People have much nicer manners when they are face to face and they
    >> need to be concerned about the condition of such after an exchange.

    >
    > Never let anyone's post bother you. Watch them for awhile to see if
    > they are worth your time, kill file them if they are of no use.
    >
    > Anytime I run into a mess/problem like yours, I'll put the variable
    > element into a config file, source it in a script, and use a variable in the
    > scripts.
    >
    > As an application programmer, I put lots of tests in my scripts to
    > verify nodes I need, database listners, mount points
    > needed by my app were realy there. When a check failed, it would
    > create a message file, and call the nofity funcition with who to
    > contact, subject, filename of problem description.
    > Example email variable names: $dba, $sysops, $crash, $coder, $mgr,
    > $sysadmin, $fyi...
    >
    > Notify function would then add in node, time, script name, application
    > and call mailx -s "$2" $1 < $3
    >
    > That reduced the O dark thirty calls to me when my production scripts
    > aborted because of external failures.
    > Also allowed me to run the scripts on the development and test
    > bed systems without bothering the production group by changing names
    > in my config file.


    Sounds to me like you could use a system like GNATS: http://www.gnu.org/software/gnats/ with a nice send-pr.

    --
    ( When in doubt, use brute force. -- Ken Thompson 1998 )

  14. Re: Finding all e-mail addresses in files on server.

    On Mon, 04 Apr 2005 13:21:38 GMT, c0ldbyte wrote:
    >
    > Sounds to me like you could use a system like GNATS:
    > http://www.gnu.org/software/gnats/ with a nice send-pr.


    I hear you talking, but in strict control environment, sysopts would
    windup in control on nats and I would not be able to make a change in
    rules until the second Sunday of the month, after the change control
    board approved my change submitted 7 days in advance of the change
    date. :-(

    Much easier to submit a change to copy in a no impact config file for
    10pm.


  15. Re: Finding all e-mail addresses in files on server.


    Chris F.A. Johnson wrote:
    > On Mon, 04 Apr 2005 at 02:37 GMT, ifoutch@gmail.com wrote:
    > > I have posted as ifoutch@yahoo.com and possibly even as
    > > ifoutch@hotmail.com. I am a newbie SA trying to find my way in my

    new
    > > job.
    > >
    > > The reason for needing to extract mail addresses is that different
    > > "admins" have created scripts that functioned as some sort of

    monitor
    > > and notification system. The problem is that the notification may

    not
    > > be going to an address that will be of any use anymore. So I am

    trying
    > > to track these down and either retire the scripts or change the

    address
    > > to something appropriate.
    > >
    > > -- Ian Foutch
    > > P.S. Nice manners you have when addressing someone you know nothing
    > > about!

    >
    > Don't bother responding to our resident kook. Most people here

    have
    > killfiled him.


    I finally figured that out. Alan Conner = AC = Anonymous Coward.
    I learned that one from the FAQ on slashdot.
    "Don't feed the trolls"

    >
    > --
    > Chris F.A. Johnson

    http://cfaj.freeshell.org/shell
    >

    ================================================== =================
    > Everything in moderation -- including moderation



  16. Re: Finding all e-mail addresses in files on server.

    In article <2124e.4754$x4.4607@newsread1.news.pas.earthlink.ne t>, Alan Connor
    wrote:
    > On comp.unix.shell, in
    ><1112582256.601080.108550@z14g2000cwz.googlegroups. com>,
    > "ifoutch@gmail.com" wrote:
    >
    >
    >> I have posted as ifoutch@yahoo.com and possibly even as
    >> ifoutch@hotmail.com. I am a newbie SA trying to find my way in
    >> my new job.
    >>
    >> The reason for needing to extract mail addresses is that
    >> different "admins" have created scripts that functioned as
    >> some sort of monitor and notification system. The problem is
    >> that the notification may not be going to an address that will
    >> be of any use anymore. So I am trying to track these down and
    >> either retire the scripts or change the address to something
    >> appropriate.
    >>
    >> -- Ian Foutch P.S. Nice manners you have when addressing
    >> someone you know nothing about!
    >>

    >
    > That's the problem, fool: I don't know anything about you.
    >
    > Except that you want to extract email addresses from a bunch
    > of files. Which is what spammers do.
    >
    > Like whether you tell the truth or not on the Usenet.
    >
    > And I can't search your posting history to find out, and
    > have no idea whether you have anything to do with any
    > formal organization at all.
    >
    > What company do you work for? What's your name so that I
    > can ask them if you work there?
    >
    > Are you ashamed of them? Is that why you don't use the name?
    >
    > What's wrong with the RCN Corporation in Princeton N.J.?
    >
    > Do they know that you are using their computers or connection?
    >
    > What I do know about you is that you are hiding by changing
    > your alias regularly and are evasive about even that.
    >
    > Like I said: **** Off.
    >
    > AC


    Is it just me, or have you been forgetting your meds more frequently?

    Oh, and don't bother, I know - I've been killfiled, right?

    Kevin

  17. Re: Finding all e-mail addresses in files on server.

    In article <1112576768.533990.100930@z14g2000cwz.googlegroups. com>, ifoutch@gmail.com wrote:
    > Looking for advice and/or examples on how to audit a server to find all
    > possible e-mail addresses listed in files. Need to verify and possibly
    > consolidate addresses for server monitoring and administration. What I
    > have been doing is greping thru the filesystem and checking for
    > matches to entries in /etc/mail/aliases, /etc/password and any lines
    > containing "mail" (case insensitive) or "@" in crontabs, and scripts.
    >
    > What I would like to do is create an exclude list of certain
    > directories. Then go through the remaining dirs. and extract mail
    > addresses and print them to a file with the filename. This would be run
    > on a production systems during off hours but still needs to be "nice"
    > to system resources. I want to automate this as much as possible. So
    > that we can periodically do an audit of all our systems.
    >
    > Has anybody done anything like this previously? Any pointers or advice
    > greatly appreciated.
    >


    Since this topic (recursively searching) comes up a lot, I'm posting a shar
    file (shell archive) of one of my favorite tools ever. This script called
    'rgrep' uses Perl and is very quick and powerful. It uses Perl's regexp engine,
    which is more powerful than a grep, too.

    Save the text below as 'rgrep.shar' and then run "sh rgrep.shar". It will
    create rgrep. Run 'rgrep -h' for help.

    Before I post it, I should mention that searching for email addresses sounds
    like a trivial task, but see the O'Reilly book 'Mastering Regular Expressions'
    for the regexp that actually matches all valid email addresses per the RFCs -
    its just under 6600 characters! It might be simpler to search for all the mail
    programs such as sendmail, mail, mailx, pine, elm, etc...

    Kevin

    --- Cut Here ---
    #!/bin/sh
    # This is a shell archive (produced by GNU sharutils 4.2.1).
    # To extract the files from this archive, save it to some FILE, remove
    # everything before the `!/bin/sh' line above, then type `sh FILE'.
    #
    # Made on 2005-04-04 14:08 PDT by .
    # Source directory was `/util/bin'.
    #
    # Existing files will *not* be overwritten unless `-c' is specified.
    #
    # This shar contains:
    # length mode name
    # ------ ---------- ------------------------------------------
    # 6119 -rwxrwxr-x rgrep
    #
    save_IFS="${IFS}"
    IFS="${IFS}:"
    gettext_dir=FAILED
    locale_dir=FAILED
    first_param="$1"
    for dir in $PATH
    do
    if test "$gettext_dir" = FAILED && test -f $dir/gettext \
    && ($dir/gettext --version >/dev/null 2>&1)
    then
    set `$dir/gettext --version 2>&1`
    if test "$3" = GNU
    then
    gettext_dir=$dir
    fi
    fi
    if test "$locale_dir" = FAILED && test -f $dir/shar \
    && ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
    then
    locale_dir=`$dir/shar --print-text-domain-dir`
    fi
    done
    IFS="$save_IFS"
    if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
    echo=echo
    else
    TEXTDOMAINDIR=$locale_dir
    export TEXTDOMAINDIR
    TEXTDOMAIN=sharutils
    export TEXTDOMAIN
    echo="$gettext_dir/gettext -s"
    fi
    if touch -am -t 200112312359.59 $$.touch >/dev/null 2>&1 && test ! -f 200112312359.59 -a -f $$.touch; then
    shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'
    elif touch -am 123123592001.59 $$.touch >/dev/null 2>&1 && test ! -f 123123592001.59 -a ! -f 123123592001.5 -a -f $$.touch; then
    shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'
    elif touch -am 1231235901 $$.touch >/dev/null 2>&1 && test ! -f 1231235901 -a -f $$.touch; then
    shar_touch='touch -am $3$4$5$6$2 "$8"'
    else
    shar_touch=:
    echo
    $echo 'WARNING: not restoring timestamps. Consider getting and'
    $echo "installing GNU \`touch', distributed in GNU File Utilities..."
    echo
    fi
    rm -f 200112312359.59 123123592001.59 123123592001.5 1231235901 $$.touch
    #
    if mkdir _sh15995; then
    $echo 'x -' 'creating lock directory'
    else
    $echo 'failed to create lock directory'
    exit 1
    fi
    # ============= rgrep ==============
    if test -f 'rgrep' && test "$first_param" != -c; then
    $echo 'x -' SKIPPING 'rgrep' '(file already exists)'
    else
    $echo 'x -' extracting 'rgrep' '(text)'
    sed 's/^X//' << 'SHAR_EOF' > 'rgrep' &&
    #!/usr/bin/perl
    X
    die "Usage: rgrep [-iredblL] regexp filepat ...\n rgrep -h for help\n"
    X if $#ARGV < $[;
    X
    # Written by Piet van Oostrum
    # This is really free software
    X
    # added "-n" option for name-only
    X
    $nextopt = 1;
    $igncase = '';
    $regpat = 0;
    $links = 0;
    $error = 0;
    $skipbin = 1;
    $debug = 0;
    $nameonly = 0;
    X
    do { $regexp = shift (@ARGV); } while &checkopt ($regexp);
    $icreg = $igncase;
    $igncase = '';
    X
    eval 'sub grep_file {
    X while () {
    X $ln++;
    X if (/$regexp/o' . $icreg .') {
    X if (! $nameonly)
    X {
    X print "$file:$ln:$_";
    X print "\n" if substr($_, -1, 1) ne "\n";
    X }
    X else
    X {
    X print "$file\n";
    X last;
    X }
    X }
    X }
    }';
    X
    for (@ARGV) {
    X if (! &checkopt ($_)) {
    X if ($igncase || $regpat || /[?*[]/ || ! -e) {
    X if ($regpat) {
    X s/#/\\#/g;
    X $_ = "#$_#";
    X } else { # translate File pattern into regexp
    X $re = '#($|/)'; $save = $_;
    X while (/[[*?+()|.^$#]/) {
    X $re .= $`;
    X $c = $&;
    X $_ = $';
    X if ($c eq '*') { $c = '[^/]*'; }
    X elsif ($c eq '?') { $c = '[^/]'; }
    X elsif ($c eq '[') {
    X if (/.\]/) { $c = "[$`$&"; $_ = $'; }
    X else {
    X $error++;
    X printf stderr "Illegal filepattern %s\n", $save;
    X }
    X } else { $c = "\\$c"; }
    X $re .= $c;
    X }
    X $_ = "$re$_\$#$igncase";
    X }
    X print "filepat: $_\n" if $debug;
    X push (@filepat, $_);
    X }
    X else { push (@files, $_); print "file: $_\n" if $debug; }
    X }
    }
    X
    exit 1 if $errors ;
    X
    if ($#filepat < $[) {
    n_pat {1;}" ;
    }
    else {
    X $subtxt = 'sub in_pat { local ($f) = @_;';
    X $or = "";
    X for (@filepat) {
    X $subtxt .= $or . '$f =~ m' . $_;
    X $or = " || ";
    X }
    X $subtxt .= ';};1';
    X
    X if (! eval $subtxt) {
    X print $@;
    X exit 1;
    X }
    }
    X
    @files = (".") if $#files < $[;
    X
    for $file (@files) {
    X &do_grep ($file);
    }
    X
    sub do_grep {
    X local ($file) = @_;
    X local (*F, $ln, $f, $g, @dirfiles);
    X if (-f $file) {
    X if (open (F, $file)) {
    X if (-B $file) { # binary file -- may be compressed/compacted
    X if (($cx1 = getc(F)) eq "\377" && (getc(F) eq "\037")) {
    X open (F, "uncompact < $file|");
    X if ($skipbin && -B $file) { close (F); return; }
    X }
    X elsif ($cx1 eq "\037" && (getc(F) eq "\235")) {
    X open (F, "uncompress < $file|");
    X if ($skipbin && -B $file) { close (F); return; }
    X }
    X elsif ($skipbin) {
    X close (F); return;
    X }
    X }
    X print "Reading $file\n" if $debug;
    X &grep_file;
    X } else {
    X print stderr "Cannot open $file\n";
    X }
    X }
    X elsif (-d $file) {
    X print "Entering $file\n" if $debug;
    X if (opendir (F, $file)) {
    X @dirfiles = readdir (F);
    X closedir (F);
    X for $f (@dirfiles) {
    X next if ($f eq '.' || $f eq '..');
    X $g = "$file/$f";
    X next if (-l $g && ($links < 1 || $links == 1 && -d $g));
    X if (-f $g && &in_pat ($g) || -d _) {
    X &do_grep ($g);
    X }
    X }
    X } else {
    X print stderr "Can't open $file\n";
    X }
    X }
    }
    X
    sub checkopt {
    X local ($_) = $_[0];
    X if (/^-/ && $nextopt) {
    X $nextopt = 1;
    X @opt = split (/-*/,$_); shift (@opt);
    X for $opt (@opt) {
    X if ($opt eq 'i') { $igncase = 'i'; }
    X elsif ($opt eq 'd') { $debug = 1; }
    X elsif ($opt eq 'l') { $links = 1; }
    X elsif ($opt eq 'L') { $links = 2; }
    X elsif ($opt eq 'b') { $skipbin = 0; }
    X elsif ($opt eq 'r') { $regpat = 1; }
    X elsif ($opt eq 'e') { $nextopt = 0; }
    X elsif ($opt eq 'n') { $nameonly = 1; }
    X elsif ($opt eq 'h' || $opt eq 'H') { & help; }
    X else { $error++; printf stderr "Unknown option -%s\n", $opt; }
    X }
    X return 1;
    X }
    X $nextopt = 1;
    X return 0;
    }
    X
    sub help {
    X print <<'HELP'; exit 0;
    Usage: rgrep [-iredblLn] regexp filepat ...
    X regexp = perl regular expression to search
    X filepat ... = a list of files and directories to be searched or
    X file patterns to match filenames.
    X filepat will be interpreted as file or directory name if it exists
    X as such, and does not contain the metacharacters [ ] ? or *. After
    X the options -i and -r all filepats will be considered patterns.
    X rgrep will search all files in any of the directories given (and its
    X subdirectories) that match any of the filepats, except binary files.
    X Compressed files will be searched in uncompressed form.
    X Note: filepats may contain / contrary to find usage.
    X -b Don't skip binary files.
    X -i Ignore case, either in the regexp or in filename matching (depending
    X on the location). Before the regexp only applies to the regexp,
    X otherwise to the filepats following it.
    X -r The following filepats are treated as real perl regexps rather than
    X shell style filename patterns. In this case / is not a special
    X character, i.e. it is matched by . and matching is not anchored (you
    X must supply ^ and $ yourself). E.g. a.b matches the file /xa/by/zz.
    X -l Do follow symbolic links only for files (default is do not follow).
    X -L Do follow symbolic links for files and directories.
    X -e Do not interpret following argument as option. Useful if regexp or
    X filepat starts with a -.
    X -d Debugging: Give a lot of output on what happens.
    X -n print only the filename of matching files.
    X -h print this message and exit.
    Piet van Oostrum
    HELP
    }
    SHAR_EOF
    (set 20 04 01 21 13 58 13 'rgrep'; eval "$shar_touch") &&
    chmod 0775 'rgrep' ||
    $echo 'restore of' 'rgrep' 'failed'
    if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
    && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'rgrep:' 'MD5 check failed'
    1eb760efd19050c0bc7911504e83dc45 rgrep
    SHAR_EOF
    else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'rgrep'`"
    test 6119 -eq "$shar_count" ||
    $echo 'rgrep:' 'original size' '6119,' 'current size' "$shar_count!"
    fi
    fi
    rm -fr _sh15995
    exit 0


+ Reply to Thread