//Web Panel

Automated WHM Health Checks: Setup & Email Digests Guide

Automate daily WHM health checks on AlmaLinux or Ubuntu with a lightweight Bash script, cron scheduling, and email alerts for uptime, resources, and service status.

5 min read
Automated WHM Health Checks: Setup & Email Digests Guide

Introduction

For a web-hosting business or a developer managing multiple sites, keeping a WHM/cPanel server healthy is vital. WHM offers built-in monitoring, but many administrators prefer a lightweight, automated script that runs daily, checks the most critical metrics, and sends a concise email digest. This article shows how to build such a script, schedule it with cron, and configure email delivery on both AlmaLinux/RHEL and Debian/Ubuntu hosts.

1. Prerequisites

  • Root or sudo access to the server.
  • WHM/cPanel installed and operational.
  • An MTA such as exim (default on WHM) or postfix installed.
  • Basic familiarity with the command line.

2. Install Required Utilities

The script uses a handful of command-line tools. Install them with your distribution’s package manager.

AlmaLinux / Rocky Linux / RHEL (dnf)

# dnf install -y sysstat net-tools mailx
  • sysstat supplies iostat and mpstat for CPU/disk I/O.
  • net-tools provides ifconfig for quick network checks.
  • mailx is a simple mail client that works with Exim.

Debian / Ubuntu (apt)

# apt update
# apt install -y sysstat net-tools mailutils
  • mailutils offers the mail command compatible with Postfix or Exim.

Note: The steps below assume a Linux host, which is the standard environment for WHM.

3. Create the Health-Check Script

Save the following Bash script as /usr/local/sbin/whm-healthcheck.sh. Replace RECIPIENT with the email address that should receive the digest.

#!/bin/bash
# ------------------------------------------------------------------
# WHM Server Health Check – Automated Digest
# ------------------------------------------------------------------
# Author: AtoZNode Blog Team
# Tested on: AlmaLinux 9, Ubuntu 22.04
# ------------------------------------------------------------------

RECIPIENT="admin@example.com"
REPORT=$(mktemp /tmp/whm-health.XXXXXX)

section() {
    echo -e "\n=== $1 ===\n" >> "$REPORT"
}

section "Uptime & Load"
uptime >> "$REPORT"

section "Disk Usage"
df -h /home /var | grep -E '^Filesystem|/home|/var' >> "$REPORT"

section "Inode Usage"
df -i /home /var | grep -E '^Filesystem|/home|/var' >> "$REPORT"

section "Memory & Swap"
free -h >> "$REPORT"

section "CPU Statistics"
mpstat 1 1 >> "$REPORT"

section "Disk I/O"
iostat -dx 1 1 >> "$REPORT"

section "Network Interfaces"
ifconfig -a | grep -E '^[a-zA-Z]' -A1 >> "$REPORT"

section "WHM Service Status"
systemctl is-active cpsrvd httpd mysqld exim | awk '{print $1 ": " $2}' >> "$REPORT"

section "cPanel Error Log (last 20 lines)"
tail -n 20 /usr/local/cpanel/logs/error_log >> "$REPORT"

section "Exim Mail Queue"
exim -bpc >> "$REPORT"

if command -v mailx >/dev/null 2>&1; then
    mailx -s "Daily WHM Health Report - $(date +%F)" "$RECIPIENT" < "$REPORT"
elif command -v mail >/dev/null 2>&1; then
    mail -s "Daily WHM Health Report - $(date +%F)" "$RECIPIENT" < "$REPORT"
else
    echo "No mail client found. Install mailx or mailutils." >&2
fi

rm -f "$REPORT"

Key command explanations:

  • uptime – shows system uptime and load averages.
  • df -h – human-readable disk space for /home and /var.
  • df -i – inode usage, which can trigger “disk full” errors even when space remains.
  • free -h – memory and swap consumption.
  • mpstat – per-CPU usage snapshot.
  • iostat – device-level I/O statistics.
  • ifconfig – view network interfaces and IP addresses.
  • systemctl is-active – checks that core WHM services are running.
  • tail – retrieves the latest entries from the cPanel error log.
  • exim -bpc – prints the number of messages in the mail queue.

4. Make the Script Executable

Set permissions so that only root can edit the script, but the cron daemon can execute it.

AlmaLinux / RHEL

# chmod 750 /usr/local/sbin/whm-healthcheck.sh
# chown root:root /usr/local/sbin/whm-healthcheck.sh

Debian / Ubuntu

# chmod 750 /usr/local/sbin/whm-healthcheck.sh
# chown root:root /usr/local/sbin/whm-healthcheck.sh

5. Schedule the Script with Cron

Run the health check every day at 02:00 AM, a low-traffic window for most Indian hosting environments.

AlmaLinux / RHEL

# crontab -l > /tmp/crontab.tmp
# echo "0 2 * * * /usr/local/sbin/whm-healthcheck.sh" >> /tmp/crontab.tmp
# crontab /tmp/crontab.tmp
# rm -f /tmp/crontab.tmp

Debian / Ubuntu

# crontab -l > /tmp/crontab.tmp
# echo "0 2 * * * /usr/local/sbin/whm-healthcheck.sh" >> /tmp/crontab.tmp
# crontab /tmp/crontab.tmp
# rm -f /tmp/crontab.tmp

Explanation of the cron line:

  • 0 2 * * * – minute 0, hour 2 (02:00 AM) every day.
  • Full path to the script ensures cron can locate it without relying on $PATH.

6. Verify Email Delivery

Test the mail delivery manually before relying on the automated digest.

AlmaLinux / RHEL

# echo "Test message from WHM health-check script" | mailx -s "WHM Test" admin@example.com

Debian / Ubuntu

# echo "Test message from WHM health-check script" | mail -s "WHM Test" admin@example.com

If the message does not arrive, inspect the MTA logs (/var/log/exim_mainlog for Exim or /var/log/mail.log for Postfix) and verify that outbound connections on port 25 (or the submission port used by your provider) are allowed.

7. Optional Enhancements

  • Log rotation: Append > /var/log/whm-health.log 2>&1 to the cron line and configure logrotate to keep a limited number of logs.
  • Threshold alerts: Add if statements to compare CPU load or disk usage against a limit and prepend “ALERT:” to the email subject.
  • JSON output: Replace plain-text sections with jq-compatible JSON for integration with monitoring platforms like Grafana.

Conclusion

Automating daily health checks removes guesswork from routine maintenance. By installing standard utilities, creating a concise Bash script, and scheduling it with cron, you receive a single email each morning that highlights uptime, resource usage, service status, and any emerging issues. This approach works on both AlmaLinux/RHEL and Debian/Ubuntu, giving you flexibility while staying within the familiar Linux toolset. Regularly reviewing the digest helps you act before small problems become service-affecting outages, keeping your hosted sites and applications running smoothly for Indian users.

whmcpanellinux health checkcron jobemail monitoringsysstatmailutilsserver administration

Try it on your own server

Follow along on a Cloud VPS with full root access, or read the step-by-step knowledge base guides.