Shell Script to Detect Missing Mount Points on Linux
Mount points are critical for ensuring proper access to filesystems in any Linux environment. Whether you’re working with cloud servers, NFS shares, or local disks, it’s essential to know if something gets unmounted or fails silently.
A simple yet powerful shell script that helps detect missing mount points by comparing two snapshots of the system’s mounted filesystems.
Prerequisites:
Before running the script, make sure you have:
- Bash Shell – This script is written for bash and tested on Linux
- Two files:
- One from a previous run (e.g.
/home/labex/project/disk_old_20-06-2025.txt
) - The new one is created automatically by the script
- One from a previous run (e.g.
- Permissions – You may need to run it with root or sudo if
df -Th
needs access
What This Script Actually Does:

This shell script compares two files:
- A previously saved list of mount points (from a known good state)
- A fresh list of current mount points (collected using
df -Th
)
The script will:
- Detect mount points that existed before but are now missing
- Print those missing mount points
- Save full details of the missing entries for troubleshooting
This is especially useful in production environments where automatic detection of missing filesystems can prevent failures in apps, backups, or services.
Click here to go to the GitHub repos link
Usage Instructions:
- Save an old snapshot of the mount points list:
df -Th > /home/labex/project/disk_old_20-06-2025.txt
- Download or create the script (see full script below)
#!/bin/bash
###############################################################################
# Script Name : compare_mount_points.sh
# Description : Compares two filesystem reports and identifies missing mount points in the second report. Outputs full details for each.
# Author : Krishna Tummeti
# Website : https://techbasehub.com
# Date : 20-Jul-2025
###############################################################################
# FILE1 = Old known-good mount point list (taken previously)
# FILE2 = Current system mount point output
df -Th > /home/labex/project/mount_point_new.txt
# Input files
FILE1="/home/labex/project/disk_old_20-06-2025.txt"
FILE2="/home/labex/project/mount_point_new.txt"
# Output files
BASE_DIR="/home/labex/project"
TMP1="$BASE_DIR/file_system_old.txt"
TMP2="$BASE_DIR/file_system_new.txt"
RESULTS="$BASE_DIR/results.txt"
FULL_RESULTS="$BASE_DIR/missing_mount_details.txt"
# Clear previous outputs
> "$RESULTS"
> "$FULL_RESULTS"
# Extract mount points (column 7), skip headers
awk 'NR > 1 {print $7}' "$FILE1" > "$TMP1"
awk 'NR > 1 {print $7}' "$FILE2" > "$TMP2"
# Compare and find mount points only in FILE1 (missing in FILE2)
comm -23 <(sort "$TMP1") <(sort "$TMP2") > "$RESULTS"
# Check if anything is missing
if [ ! -s "$RESULTS" ]; then
echo "All mount points from '$FILE1' are present in '$FILE2'."
else
echo "Missing mount points detected! Details below:"
# Use FOR loop to process and extract full lines
for mount_point in $(cat "$RESULTS"); do
grep -F "$mount_point" "$FILE1" >> "$FULL_RESULTS"
done
cat "$FULL_RESULTS"
echo
echo "Full details saved in: $FULL_RESULTS"
fi
- Make the script executable:
chmod +x compare_mount_points.sh
- Run the script:
./compare_mount_points.sh
- Review the output:
- If everything is fine, it prints a confirmation.
- If something is missing, it shows details and saves them to a results file.
- Automating It:
If you want this to run daily (or hourly), you can add it to cron:
0 8 * * * /home/labex/project/compare_mount_points.sh >> /home/labex/project/mount_check.log 2>&1
