Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

SOLVED What file contains a list of usernames and the main account domain?

Discussion in 'General Discussion' started by Ishware, Jan 14, 2018.

  1. Ishware

    Ishware Well-Known Member

    Joined:
    Nov 7, 2003
    Messages:
    193
    Likes Received:
    3
    Trophy Points:
    168
    Location:
    Panama City, FL
    cPanel Access Level:
    Root Administrator
    So another thread led me to /etc/domainusers, which is *almost* exactly what I need, except that it contains all the domains in use for each user.

    What I need is something I can grep from bash that will return a username *once* with its corresponding main domain.

    Or is there a way to query cPanel's setup somehow to return this from bash?

    Basically, if you have the username as $user and do
    Code:
    grep ': $user' /etc/userdomains
    , you get something like
    Code:
    example.com: username
    - which is perfect, except you get multiple domains if they have addon domains. I need something that will allow me to only get the primary domain associated with an account.

    Any ideas? :)
     
  2. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,651
    Likes Received:
    73
    Trophy Points:
    328
    cPanel Access Level:
    Root Administrator
    cat /var/cpanel/users/%user% | grep ^DNS= | sed s/^DNS=//g
     
  3. Ishware

    Ishware Well-Known Member

    Joined:
    Nov 7, 2003
    Messages:
    193
    Likes Received:
    3
    Trophy Points:
    168
    Location:
    Panama City, FL
    cPanel Access Level:
    Root Administrator
    You are magic. Thank you so so very much. :)
     
  4. 24x7server

    24x7server Well-Known Member

    Joined:
    Apr 17, 2013
    Messages:
    1,786
    Likes Received:
    82
    Trophy Points:
    78
    Location:
    India
    cPanel Access Level:
    Root Administrator
    There is much simpler way than using a complex sed and grep combination when there is already a file that has the data that you are looking for.

    /etc/userdomains contains list of all Addon and Subdomain. If you want just get a list of main account and its user, use trueuserdomains.

    # cat /etc/trueuserdomains
    This is the file that contains a list of the main domain and their respective usernames..
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. cPWilliamL

    cPWilliamL cP Technical Analyst II
    Staff Member

    Joined:
    May 15, 2017
    Messages:
    257
    Likes Received:
    29
    Trophy Points:
    103
    Location:
    America
    cPanel Access Level:
    Root Administrator
    Just to follow up with a few examples:
    Code:
    # whmapi1 listaccts search='^cptest$' searchtype=user|grep -oP '(?<=domain: ).+'
    cptest.tld
    
    # grep -oP "[^:]+(?=: cptest$)" /etc/trueuserdomains
    cptest.tld
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice