Nk_user
Description
The function nk_user()
expects to be passed a domain name and returns the username associated with that domain. It uses grep
-E to search for the domain in /etc/userdomains
, and awk
to print the second field (the username). If no domain name is provided, the script returns an error message.
Example
[root@cloudvpsserver ~]# nk_user nkern.net nkern
Code
nk_user() { # nk_user expects to be passed a domain name. Fail if not. domain="$1" if [ "$1" = "" ]; then echo "You must provide a domain name" return 0 fi # Using grep -E to find the domain in userdatadomains. # Need the ^ to denote that it's the start of the line and the : to end off the search. This helps prevent matching subdomains. # And the docroot is the 2nd field in /etc/userdatadomains grep -E "^$domain:" /etc/userdomains | awk '{print $2}' }