Monday, 18 November 2013

Script to list all cPanel accounts under specific reseller

To list of all cPanel accounts under a specific reseller account, then you can  use the this simple shell script.

root@server[#] vi listreseller.sh
 #!/bin/bash
usage()
{
echo "Example : $0 domain.com or username"
exit 1
}

test $1 || usage
USERN=$(grep $1  "/etc/userdomains" | awk '{print $NF}' | awk 'NR==1')

if [[ -z $USERN ]]
then
echo -e "e[1;33m $1 is not a reseller e[0m"

exit 1

fi

OWNER=`cut -d: -f1  /var/cpanel/resellers | grep -o $USERN`
exitstatus=$?

if [ "$exitstatus" == 0 ] ; then
echo  "=========================================================="
echo -e  "e[1;31m Below are the accounts associated with the reseller $name e[0m"
echo "=========================================================="

output=$(for i in `grep $OWNER /var/cpanel/users/* -l` ; do grep USER= $i ; done | awk -F"=" '{ print $2 }')
echo -e   "e[1;33m $output e[0m"
else
echo -e  "e[1;35m  $1  is not  a Reseller  e[0m"
exit

fi

 

root@server[#] chmod +x listreseller.sh

Copy the above script in a .sh file like listreseller.sh and allow executable permission to listreseller.sh file and then execute it as:

root@server[#] ./listreseller resellerusername

root@server[#] ./listreseller resellerdomain.net

After executing the script you will get the below output as ::

root@server[#] ./listreseller linuxeasy.net
==========================================================
Below are the accounts associated with the reseller
==========================================================
linuxeasy
servertech
jpssolu

root@server[#] ./listreseller linuxeasy1
linuxeasy1 is not a reseller

** Its all About to share **

No comments:

Post a Comment