Bash

Disk Space Alert

admin by @admin ADMIN
2d ago
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
Cron-friendly script that checks disk usage on each filesystem and emails (or webhooks) if any partition exceeds a threshold.
Bash
Raw
#!/usr/bin/env bash
THRESHOLD=85       # percent

df -P -h | awk -v t="$THRESHOLD" 'NR>1 {
    sub(/%/,"",$5)
    if ($5+0 >= t) {
        printf "ALERT: %s is %d%% full (mounted on %s)\n", $1, $5, $6
    }
}'

# Send via webhook if anything alerted
output="$(df -P -h | awk -v t="$THRESHOLD" 'NR>1 {sub(/%/,"",$5); if ($5+0>=t) print $0}')"
if [[ -n "$output" ]]; then
    curl -s -X POST -H "Content-Type: application/json" \
        -d "{\"text\":\"Disk alert on $(hostname):\n\`\`\`$output\`\`\`\"}" \
        "$SLACK_WEBHOOK"
fi
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.