Last active
December 6, 2018 13:47
-
-
Save iPublicis/1adc01b0fcdbceee77cf05143493f4a8 to your computer and use it in GitHub Desktop.
cPanel mass delete e-mail accounts script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
########################## | |
# | |
# Taken from https://forums.cpanel.net/threads/mass-delete-e-mail-accounts-script.387802/ | |
# Created by QuizKnows - https://forums.cpanel.net/members/quizknows.178313/ | |
# | |
if [ -z $2 ] | |
then | |
echo "Usage: $0 CPANEL_USERNAME MAIL_DOMAIN" | |
exit 0 | |
fi | |
#define username/domain | |
username=$1 | |
domain=$2 | |
#define mail directory | |
eval homedir="$(printf "~%q" "$username")" | |
maildir=$homedir/etc/$domain | |
#sanity check, make sure directory exists in expected location. | |
if [ -d $maildir ] | |
then | |
echo "$maildir exists in expected location" | |
else echo "$maildir does not exist. Check username and domain are correct, and that e-mail accounts exist for this domain. Exiting" | |
exit 1 | |
fi | |
#ARE YOU SURE??? | |
echo "this will PERMANANTLY remove ALL e-mail accounts from $domain." | |
echo "are you SURE you want to do this? Type YES in all caps to confirm." | |
read confirmation | |
if [[ "$confirmation" == "YES" ]] | |
then | |
echo confirmed | |
else | |
echo "Did not confirm, exiting" | |
exit 0 | |
fi | |
#one more sanity check | |
if [ -x /scripts/delpop ] | |
then | |
echo "/scripts/delpop exists. Continuing." | |
else | |
echo "/scripts/delpop not found on your system. Make sure you are running a current cPanel version" | |
exit 1 | |
fi | |
#the real "meat" of the script. Point of no return. | |
/bin/cut -d':' -f 1 $maildir/shadow > /tmp/acctlist | |
if [ -s /tmp/acctlist ] | |
then | |
for each in `cat /tmp/acctlist` ; do /scripts/delpop --email=$each@$domain ; done | |
else | |
echo "no accounts found or other error. Check $maildir/shadow" | |
exit 1 | |
fi | |
rm -f /tmp/acctlist | |
#thats all folks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment