Edit File: get_reseller_accounts.sh
#!/bin/bash # Filename: get_reseller_domains.sh # This script prints each reseller's cPanel users and their primary domain. # Output file output_file="/usr/local/cptools/textfiles/reseller_domains.txt" > "$output_file" # Clear the file before writing rm -f $output_file # Read the list of reseller usernames from /var/cpanel/resellers # Typically lines look like "reseller1: root", so we split on ":" and take the first field resellers=$(awk -F: '{print $1}' /var/cpanel/resellers) # Loop through each reseller for reseller in $resellers; do echo "Reseller : $reseller" >> "$output_file" echo "=============" >> "$output_file" # For each reseller, find cPanel accounts where OWNER=reseller for userfile in $(grep -l "OWNER=$reseller" /var/cpanel/users/*); do user=$(basename "$userfile") # Extract the main domain from the DNS= line in the user's file domain=$(grep '^DNS=' "$userfile" | cut -d= -f2) # If there's no DNS= line, set domain to a placeholder if [ -z "$domain" ]; then domain="(no domain found)" fi echo "$user ($domain)" >> "$output_file" done echo "" >> "$output_file" done echo "Output written to $output_file"