The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Find any accounts without default set to :fail:

Discussion in 'General Discussion' started by mambovince, Jun 7, 2008.

  1. mambovince

    mambovince Well-Known Member

    Joined:
    Jan 15, 2005
    Messages:
    192
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    London, UK
    Hi,
    How can we find out if any accounts don't have default set to :fail: no such address here

    I have it set as such in WHM, but maybe some clients have changed it.
    Is there an SSH command to find them easily, instead of manually using cPanel for 150 accounts?

    Many thanks,

    - Vince
     
  2. mtindor

    mtindor Well-Known Member

    Joined:
    Sep 14, 2004
    Messages:
    1,281
    Likes Received:
    37
    Trophy Points:
    48
    Location:
    inside a catfish
    cPanel Access Level:
    Root Administrator
    grep '\*\:' /etc/valiases/*

    or

    grep '*:' /etc/valiases/*
     
  3. mambovince

    mambovince Well-Known Member

    Joined:
    Jan 15, 2005
    Messages:
    192
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    London, UK
    Hi,
    Thanks for that, but both of those return all email accounts - with and without :fail:

    Another command I was given
    grep -vl fail ./* | wc -l
    just returns 14
    Doesn't tell me which accounts :-(

    - Vince
     
  4. mtindor

    mtindor Well-Known Member

    Joined:
    Sep 14, 2004
    Messages:
    1,281
    Likes Received:
    37
    Trophy Points:
    48
    Location:
    inside a catfish
    cPanel Access Level:
    Root Administrator
    Actually, my original answer doesn't bring up "all" accounts. It'll bring up all accounts with a catchall set -- even if it isn't set to fail.

    Easy enough to fix

    grep ':fail:' /etc/valiases/*

    You don't want to pipe it to wc unless you are looking for something like the total #.

    Just grep for :fail: and be done with it. And if you don't want to use the ' ' that's your choice. I do it out of habit because I often grep for things that need to be in single quotes.

    Mike
     
  5. mctDarren

    mctDarren Well-Known Member

    Joined:
    Jan 6, 2004
    Messages:
    664
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    New Jersey
    cPanel Access Level:
    Root Administrator
    I can't remember if I did this, or someone here suggested it or if cpanel threw it in. :)

    But if you don't see it, create a file in /scripts called setallemailstofail and put this into it:

    Code:
    #!/usr/bin/perl
    print "Converting all domain Default Accounts to :fail: ...";
    opendir (DIR, "/etc/valiases/") or die;
    while (my $file = readdir (DIR)) {
            if ($file =~ /^\./) {next}
            open (IN, "</etc/valiases/$file") or die;
            my @data = <IN>;
            close (IN);
            open (OUT, ">/etc/valiases/$file") or die;
            foreach my $line (@data) {
                    if ($line =~ /^\*\:/) {
                            print OUT "*: :fail:\n";
                    } else {
                            print OUT $line;
                    }
            }
            close (OUT);
    }
    print "Done!\n";
    
    Then create a cron in /etc/cron.daily that runs this script and outputs the result to null (or leave off the tail end if you want your daily cron email to contain the results):

    Code:
    /scripts/setallemailstofail >/dev/null 2>&1
    
    This way it runs every day so you don't have to worry about it any longer. Don't forget to set permissions on the files so that they can execute. Hope that helps!
     
    #5 mctDarren, Jun 8, 2008
    Last edited: Jun 8, 2008
  6. mambovince

    mambovince Well-Known Member

    Joined:
    Jan 15, 2005
    Messages:
    192
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    London, UK
    Hi Mike,
    Thanks but it still only returns accounts that do have default email set to :fail:
    I need the opposite.

    @serversphere,
    I looked and don't seem to have /scripts/setallemailstofail
    Interesting script though if anyone else can confirm it will work - I'm a little afraid to use on production server in case it stops ALL emails :eek:

    Many thanks,

    - Vince
     
  7. mctDarren

    mctDarren Well-Known Member

    Joined:
    Jan 6, 2004
    Messages:
    664
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    New Jersey
    cPanel Access Level:
    Root Administrator
    I did a search and it was in fact Chirpy who wrote that little gem (I knew it was a little too slick for my perl skills, lol). Here's the original thread:

    http://forums.cpanel.net/showthread.php?t=30987

    Added: Apologies to Chirpy for the stealing of thunder. ;)
    Added #2: Forgot to mention, I am running this on all of our production servers, works fine. But I recommend you back up the /etc/valiases file just to be on the safe side. Revert back if things go ca-ca.
     
    #7 mctDarren, Jun 8, 2008
    Last edited: Jun 8, 2008
  8. mtindor

    mtindor Well-Known Member

    Joined:
    Sep 14, 2004
    Messages:
    1,281
    Likes Received:
    37
    Trophy Points:
    48
    Location:
    inside a catfish
    cPanel Access Level:
    Root Administrator
    Ok, I misread. You want to see which accounts don't have :fail:, right?


    grep '\*\:' /etc/valiases/*|grep -v '\:fail\:'

    That'll first check for domains that have a catchall ( *: ), and then out of those entries it'll omit any with :fail: in them - leaving only those which are blackholes, bounces, or catchalls that are forwards to other email addresses.

    Mike
     
Loading...

Share This Page