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

Ishware

Well-Known Member
Nov 7, 2003
211
6
168
Williamsburg, VA
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? :)
 

24x7server

Well-Known Member
Apr 17, 2013
1,911
97
78
India
cPanel Access Level
Root Administrator
Twitter
Any ideas?
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..
 

cPWilliamL

cP Technical Analyst II
Staff member
May 15, 2017
258
30
103
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