#! /bin/bash
# Afrihost : cpanel accounts and user list script

# cpanel check
if ! [ -f "/usr/local/cpanel/cpanel" ]; then
       echo "No cpanel"
       exit
fi

# Only once at a time please
exec 200<$0
flock -n 200 || exit 1

# Check that the load is too high
if [ -f /proc/loadavg ] ; then
    read LOAD MORE < /proc/loadavg
    if [ ${LOAD/.*/} -ge 30 ] ; then
        echo "load to high,not running"
        exit 1  # load too high - don't bother with this other stuff right now:
    fi
fi


USAGE=$(echo -e "cplist -u [ list users from /etc/trueuserdomains ]
cplist -d [ List domains from /etc/trueuserdomains ]
cplist -a [ cat /etc/trueuserdomains ]
cplist -o [ cat /etc/trueuserowners ]")


if ! [ "$1" ] ; then 
        #echo "Need the UsersName"
        echo "$USAGE"
        exit 1
fi


if [ "$1" == "-a" ];then
        awk -F ":" '{print $1,$2}' /etc/trueuserdomains  | column -s" " -t
elif [ "$1" == "-u" ] ; then
        awk -F ": " '{print $2}' /etc/trueuserdomains
elif [ "$1" == "-d" ] ; then
        awk -F ":" '{print $1}' /etc/trueuserdomains
elif [ "$1" == "-o" ] ; then
        cat /etc/trueuserowners  | column -s" " -t
fi

