Skip to content

Instantly share code, notes, and snippets.

@rushipkar90
Created September 25, 2015 16:37
Show Gist options
  • Save rushipkar90/b55a6f86a9e90a9caccd to your computer and use it in GitHub Desktop.
Save rushipkar90/b55a6f86a9e90a9caccd to your computer and use it in GitHub Desktop.
generate_client_list.sh
#!/bin/bash
# Directory to store log files in
DST=/root/logs
# Any logs older than this will be deleted first
KEEPDAYS=5
# Create DST if it doesn't exist
if [ ! -d "$DST" ]; then
mkdir $DST
fi
# Remove logs older than KEEPDAYS in DST
find ${DST} -type f -mtime +${KEEPDAYS} -exec rm -f {} \;
# Flush
echo -n > $DST/`hostname`_clientlist_`date +%F`.csv
echo -n > $DST/tmp.dat
# Get list of all accounts
cat /etc/trueuserdomains | awk '{print $2}' > $DST/tmp.dat
# Remove suspended accounts
for spnd in `ls -A /var/cpanel/suspended/`
do
sed -i "/$spnd/d" $DST/tmp.dat
done
# Get email address and compile csv file
for lst in `cat $DST/tmp.dat`
do
echo $lst "," `grep "CONTACTEMAIL=" /var/cpanel/users/$lst | tr -s "=" " " | awk '{print $2}'` | tr -d " " >> $DST/`hostname`_clientlist_`date +%F`.csv
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment