Finding domain's username on server (easy!)

alwaysweb

Well-Known Member
Mar 8, 2002
97
0
306
Dallas, TX
cPanel Access Level
Root Administrator
I'm sure you've all scratched your head a time or two when you need to find the username for 'xyz.com' on the server, right?

This easy shell script script solution. Login to root via SSH and do this:

pico /usr/local/bin/finddom

paste in this text (between the lines, NOT including the lines):

-----------------------------------------------------------------
#!/bin/sh

OUTPUT=`grep -r "$1" /etc/trueuserdomains`

if [ "$OUTPUT" != "" ]; then

OUTPUT2=`echo $OUTPUT | cut -d":" -f2`;
echo "";
echo "$1 is username: $OUTPUT2";
echo "";

else
echo " -- NO Match --";
fi

exit 0;
-----------------------------------------------------------------

Now, set permissions on it so you can run it:

chmod 700 /usr/local/bin/finddom


Now, next time you need to find xyz.com on the server, do this from SSH:

finddom xyz.com

or

finddom xyz

(or any unique part of the domain name) and it will quickly tell you the account username.

Cpanel is welcome to include this is any Cpanel build they want, possibly in the /scripts folder...

I use this at least 10 times a day, and hope it will help you too! Enjoy! :D
 

Website Rob

Well-Known Member
Mar 23, 2002
1,504
1
318
Alberta, Canada
cPanel Access Level
Root Administrator
Nice little script and thanks for sharing.

A small bug I found though, if an account has been setup as a Sub-domain name using the Domain name of an already setup account, they will both show, but only one account ID.

As I never use the first 8 charactors of a Domain name for the account ID, I have found myself needing something for same the reason, but on the flip side. Starting with an account ID and trying to find what their Domain is, because of various checking I sometimes need to do. I 'tail' error logs a lot. :D

Having to constantly refer to WHM for a matchup, I changed a few variables and came up with:

-----------------------------------------------------------------

#!/bin/sh

OUTPUT=`grep -r "$1" /etc/trueuserdomains`

if [ "$OUTPUT" != "" ]; then

OUTPUT2=`echo $OUTPUT | cut -d":" -f1`;
echo "";
echo "$1 use's the Domain name of: $OUTPUT2";
echo "";

else
echo " -- NO Match --";
fi

exit 0;

-----------------------------------------------------------------

So I call my code 'finddom' and the code by alwaysweb, 'findid' for convienence. Wouldn't take much (I think, shall have to check it out later) to write some similar code to determine who owns the account. (i.e. which Reseller)
 

Website Rob

Well-Known Member
Mar 23, 2002
1,504
1
318
Alberta, Canada
cPanel Access Level
Root Administrator
Too complicated. :)

./scripts/whoowns domainhere

does not work, one must cd to scripts then run ./whoowns. One line commands like above are easier on the brain.

I guess one could do a sym link (for the first code posted) to that script, but how would one reverse it? Using something for finding out the owner of an account -- one line code -- would be handy though.
 

Elena

Well-Known Member
Aug 10, 2001
109
1
316
California
Why not go to WHM>Account Functions>List Accounts and then on that page just go to the bottom... enter in the domain name and hit Find button.. and poof! you've got the accounts main info right there. Seems easier to me that way :D

The list accounts page also has the option to search by owner/reseller, domain, user, package and ip address...
 
Last edited:

casey

Well-Known Member
Jan 17, 2003
2,298
0
191
Originally posted by Website Rob
Too complicated. :)

./scripts/whoowns domainhere

does not work, one must cd to scripts then run ./whoowns. One line commands like above are easier on the brain.

I guess one could do a sym link (for the first code posted) to that script, but how would one reverse it? Using something for finding out the owner of an account -- one line code -- would be handy though.
No you don't. Just type /scripts/whoowns domainhere at the prompt, and there it is.
 

Admin356

Active Member
Feb 19, 2003
25
0
151
does not work, one must cd to scripts then run ./whoowns. One line commands like above are easier on the brain.
Edit ~/.bashrc

Add

alias whoowns='/scripts/whoowns'

The next login you can simply type: whoowns domain.com :)
 

kosmo

Well-Known Member
Verifed Vendor
Aug 12, 2001
403
0
316
All over Europe
very interesting script (/scripts/whoowns) but for addon domains it will display the user that created the addon and not the username that was assigned to this specific addon domain.

Any function that will show the specific username for an addon domain? I can find it in httpd.conf but I need something similar to /scripts/whoowns

kosmo