To prevent spamming in a cPanel server, you can use the following bash script:
#!/bin/bash # Check for the presence of the cPanel utility if ! [ -x "$(command -v cpx)" ]; then echo "Error: cpx is not installed." >&2 exit 1 fi # Set the maximum number of emails allowed per hour MAX_EMAILS_PER_HOUR=100 # Get the list of email accounts on the server ACCOUNTS=$(cpx --list-accounts) # Loop through each email account for ACCOUNT in $ACCOUNTS; do # Get the current email usage for the account USAGE=$(cpx --account=$ACCOUNT --get-usage) # Check if the email usage is above the maximum allowed if [ "$USAGE" -gt "$MAX_EMAILS_PER_HOUR" ]; then # Suspend the email account cpx --account=$ACCOUNT --suspend echo "Suspended email account: $ACCOUNT" fi done
This script checks for the presence of the
cpx utility, which is used to manage cPanel accounts. It then sets a maximum number of emails allowed per hour and retrieves a list of email accounts on the server. For each email account, it checks if the email usage is above the maximum allowed. If it is, the script suspends the email account using the
Note that this script is just an example and may need to be modified to fit your specific needs. For example, you may want to adjust the maximum number of emails allowed per hour or add additional checks to prevent spamming. Additionally, you will need to set up a cron job to run this script regularly in order to continuously monitor and prevent spamming.