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.

Script to delete Suspended Account...help

Discussion in 'cPanel Developers' started by techbsl, Mar 9, 2012.

  1. techbsl

    techbsl Member

    Joined:
    Oct 9, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Hi Everyone,

    I have working a script to delete suspend accounts with X time of suspension....my problem is what the script not is removing the DNS Zone.

    The script delete the account for username

    Code:
    echo "y" | /scripts/killacct $i &>/dev/null
    where
    Code:
    $i
    is the username

    but the Zone DNS is necessary for domain, this is the code,

    Code:
    echo /usr/local/cpanel/whostmgr/bin/dnsadmin --action REMOVEZONE --data \&zone=$i
    I need capture a variable X with the domain to I can delete the DNS .

    Help me please.

    Thanks,


    JF
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    This is a known inconsistency in our product.

    killacct via the command line, unlike the WHM interface, does not automatically remove zone files from DNS by default. You need to specify the --killdns parameter when calling killacct to do what you want to do :).
     
  3. techbsl

    techbsl Member

    Joined:
    Oct 9, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Oh My god......is so easy.......ahahhaah....DavidG thank you so much for you help.....

    Take care, bye
     
  4. techbsl

    techbsl Member

    Joined:
    Oct 9, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    mmmm, one thing more......the script was running for 3 months or more......I need delete all Zone DNS old what not have account.....any suggestion?

    thanks,

    JF
     
  5. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    Unfortunately, there's not a way to map an account to its domains / dns zones after it has been removed. This means, you'll need to map all existing users to their domains and remove any DNS zones that do not get in that list.

    In order to pull in all the domains, you'll need to call:

    WHM's List Accounts ( /xml-api/listaccts || Whostmgr::Accounts::_listaccts() )

    Then for each user in list accounts:

    cPanel's API2 - DomainLookup::getdocroots() (gives you main domain and subdomains)
    cPanel's API2 - AddonDomain::listaddondomains() (gives you addon domains)
    cPanel's API2 - Park::listparkeddomains() (gives you parked domains)

    After building this list, check the domains against /var/named/$domain.db.

    I'd definitely recommend having this script show you what potential domains will be deleted.
     
  6. techbsl

    techbsl Member

    Joined:
    Oct 9, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Can someone help me with this script???

    Thanks,

    JF
     
  7. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    If you post up the code you're working on, I can provide general advice but due to the nature of the script, I don't think anyone is going to post one up. I wouldn't want to post code that could delete DNS entries from your server that were still needed by customers.

    The pseudocode/logic for the script is like so:


    Get list of all files in /var/named ending in .db.
    For each file:
    Remove the .db at the end to get your list of domains

    Get list of all cPanel users and their main domain with /xml-api/listaccts
    For each user:
    get their parked, addon and sub domains with the appropriate api2 calls.


    For each domain gotten from /var/named:
    if the domain is not in the list of all user domains, remove its DNS zone
     
Loading...

Share This Page