1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Problem Locating .forward files

Discussion in 'Linux / Unix Discussion' started by mpaddock, Sep 9, 2010.

  1. mpaddock

    mpaddock New Member

    2
    0
    1
    Okay so here is the scoop, I took over a contract for a government agency. The previous contractor left the day before we took over. They left absolutly no documentation of the system. We have 8 Solaris 9 servers that have .forward files scattered all over them. We have users that no longer want to recieve the emails that the system is producing.

    How do I locate all of the forward files on each system. I have checked to user directories and root directory and can not find a forward file with their address in it. Is there a command that I can use to search for forward files or search for their address across the system?
     
  2. FreakyBeanz

    FreakyBeanz Bit Poster

    20
    2
    13
    As "root" (or another account with suitable permissions):

    $ find / -name .forward

    That will scan the whole file system for the forward files.

    Not sure if Solaris supports the "locate" command natively (been a few years since using Solaris), but someone might have installed the open-source package for it -it's similar to "find" in some respects - if its installed on the server type:

    $ locate .forward

    If the database is out of sync with the filesystem you might not find what you're looking for, so I would recommend using the find command as it scans the live file system - or at least running an updatedb (or equivalent) if running the locate command first.
     
    Last edited: Sep 10, 2010
    Certifications: RHCT
    WIP: CompTIA Linux+
  3. mpaddock

    mpaddock New Member

    2
    0
    1
    Thank you, that appears to be working great!
     
  4. FreakyBeanz

    FreakyBeanz Bit Poster

    20
    2
    13
    A slicker way of doing this would be to search for the files you're looking for (the .forward files), and then search the contents of each .forward file found, for the hostname (or email address) you're looking for. This will save you the hassle of rummaging around lots of different files seeing if they contain the hostname you're after!

    Here's how you would do that:

    $ find / -name .forward -exec grep -q hostname {} \; -exec echo {} \;

    In this command we're again telling "find" to return all instances of the .forward files on the whole filesystem, but for each file we find, we are going to search the contents of the file using grep for the string "hostname" (of course you would replace that with the relevant string you want to look for).

    The "grep" is run in quiet mode "-q" so that it doesn't output every single .forward file name, as we're not interested in the ones that don't contain the hostname string. If we do find "hostname" in a .forward file, we echo the filename out to standard output.

    Nice and easy one-liner that'll save you a little time!

    If you're feeling totally brave you might want to actually delete the line in the file with the string from the .forward file:

    $ find / -name .forward -exec grep -q hostname {} \; -exec sed -i'.bak' '/hostname/d' {} \; -exec echo {} \;

    That will use the sed editor and will make a backup copy of the .forward file and call it .forward.bak, and delete ANY line with the string "hostname" in it - so use with CAUTION! Solaris never used to support the "-i" option in its version of sed - it may well do now, but there are other work arounds that can be done!



    Should have thought of that last night! Apologies for that.
     
    Last edited: Sep 11, 2010
    Certifications: RHCT
    WIP: CompTIA Linux+
  5. FreakyBeanz

    FreakyBeanz Bit Poster

    20
    2
    13
    I was right, the "-i" option isn't available with sed on Solaris!

    So here's how you can find, and delete the line within the file on Solaris assuming you have PERL installed!

    $ find / -name .forward -exec perl -n -i.bak -e "print unless /^hostname/" {} \; -exec echo {} \;

    This works exactly the same way as the sed example does, and also creates a ".forward.bak" backup file.
     
    Last edited: Sep 19, 2010
    Certifications: RHCT
    WIP: CompTIA Linux+

Share This Page

Loading...