How to Mass Unsuspend cPanel Accounts Using a Simple Script

Managing multiple cPanel accounts on a WHM server can be a challenge, especially when you need to perform bulk operations like unsuspending accounts. If you’ve ever had to unsuspend multiple accounts manually, you know how time-consuming it can be. In this guide, I’ll show you how to automate this process using a simple bash script that reads account usernames from a text file and unsuspends them all in one go.

Prerequisites

Before you start, make sure you have the following:

  1. Access to WHM: You need root or reseller access to the WHM server where the accounts are hosted.
  2. SSH Access: You should be able to log in to your server via SSH to execute the script.
  3. Text File with Usernames: Prepare a text file that contains the usernames of the accounts you want to unsuspend.

Step 1: Create a List of Usernames

The first step is to create a text file containing the usernames of the accounts you want to unsuspend. Each username should be on a new line.

Example domains.txt file:

exampleuser1
exampleuser2
exampleuser3
exampleuser4
exampleuser5

Place this file in a location on your server, such as /root/domains.txt.

Step 2: Write the Unsuspension Script

Next, you need to create a bash script that reads the usernames from the text file and executes the whmapi1 unsuspendacct command for each one.

Create the script:

#!/bin/bash

# Path to your text file containing the usernames
file_path="/root/domains.txt"

# Read each line in the file
while IFS= read -r domain
do
  # Unsuspend the account using whmapi1
  whmapi1 --output=jsonpretty unsuspendacct user="$domain" retain-service-proxies=0
  echo "Unsuspended account for user: $domain"
done < "$file_path"

Explanation:

  • file_path=”/root/domains.txt”: This specifies the location of your text file containing the usernames.
  • while IFS= read -r domain: This reads each line of the file (each username).
  • whmapi1 –output=jsonpretty unsuspendacct user=”$domain” retain-service-proxies=0″: This command unsuspends the account for the specified user. The retain-service-proxies=0 option ensures that no service proxies are retained.
  • echo “Unsuspended account for user: $domain”: This prints a message to the terminal confirming that the account was unsuspended.

Step 3: Make the Script Executable

Before you can run the script, you need to make it executable. You can do this with the following command:

chmod +x /root/unsuspend_accounts.sh

Step 4: Run the Script

Now, you’re ready to run the script. Execute it by typing:

./unsuspend_accounts.sh

The script will read each username from the text file and unsuspend the corresponding account. You should see a confirmation message for each account as it is unsuspended.

Conclusion

With this simple bash script, you can easily mass unsuspend cPanel accounts on your WHM server. This method saves time and reduces the risk of errors that come with manually unsuspending accounts one by one. Whether you’re a system administrator managing multiple accounts or a hosting provider dealing with large numbers of clients, this script will help streamline your workflow.

Remember to always double-check your list of usernames before running the script, as it will unsuspend every account listed in the file. Happy hosting!