WEBTOOLIST.
STATIC WEB PLATFORM
NO ACCOUNTS / NOTHING TO INSTALL

$ webtoolist --script disk-threshold-alert

Disk Threshold Alert

Exit non-zero when any mounted filesystem exceeds a usage threshold.

category Monitoring shell Bash 4+ updated 2026-08-29
diskalertmonitoringthreshold
Safety notes
  • Read-only: reads df output.
  • Treat tmpfs and container overlay mounts separately; the default excludes tmpfs.
commands involved: mount

Dependencies: df, awk

Usage

  • Set THRESHOLD (percent, default 85).
  • Wire the exit code into cron, systemd timers, or your monitoring agent.

Script

#!/usr/bin/env bash
set -euo pipefail

threshold="${THRESHOLD:-85}"
fail=0

while read -r filesystem size used avail pct mount; do
  pct="${pct%\%}"
  if ((pct >= threshold)); then
    printf 'ALERT %3s%% used on %s (%s, %s free)\n' "$pct" "$mount" "$used" "$avail" >&2
    fail=1
  else
    printf 'ok    %3s%% used on %s\n' "$pct" "$mount"
  fi
done < <(df -P -x tmpfs -x devtmpfs | tail -n +2)

exit "$fail"

Example

./disk-threshold-alert
THRESHOLD=95 ./disk-threshold-alert

Notes

  • df -P gives a stable one-line-per-filesystem format, which is what the parser relies on.
  • Inodes can run out before space does; add df -i if that has bitten you.

Related scripts

Service Health Check

Check systemd services and HTTP endpoints in one pass with a non-zero exit on failure.

Monitoring

Disk Usage Report

Show filesystem usage and the largest directories under a path.

System Administration

Find Large Files

Locate files above a size threshold and show them largest first.

File Management