Shell Script to Monitor the mounts points above desired threshold on Linux


I am going to share my script which I use to monitor the mount points on linux server.

Script:

Save script as you want and modify accordingly.

#!/bin/bash
#
# Script: mount_monitor.sh
# Version: 1.0
# Author: Himanshu Singh
# Description: Monitors  the mount points and sends email if usage exceeds 90%.

# Set email recipient
RECIPIENT="support@funoracleapps.com"

# Function to send email notification
send_email() {
    SUBJECT="Mount Point Usage Alert"
    BODY="Mount point usage exceeded 90% on the server."

    echo "$BODY" | mailx -s "$SUBJECT" "$RECIPIENT"
}

# Main script logic
THRESHOLD=90

# Get mount points and check usage
MOUNT_POINTS=$(df -h | awk '{print $6}' | sed -n '2,$p')
for MOUNT_POINT in $MOUNT_POINTS; do
    USAGE=$(df -h "$MOUNT_POINT" | awk 'NR==2 {print $5}' | sed 's/%//')
    if [ "$USAGE" -ge "$THRESHOLD" ]; then
        echo "Mount point $MOUNT_POINT usage is above $THRESHOLD%."
        send_email
    fi
done

echo "Mount point monitoring completed."


Sample Output:

[opc@ocicliserver ~]$ ./mount_monitor.sh
Mount point /boot usage is above 30%.
Mount point monitoring completed.



If you like please follow and comment