Skip to content

Alert on a disk filling up

Logs or backup files eat /var; in 24 hours the server falls over. A basic df check every 10 minutes saves a 2 AM incident.

Recipe

bash
#!/usr/bin/env bash
# /etc/cron.d/disk-watch — */10 * * * * root /opt/disk-watch.sh
THRESHOLD=${THRESHOLD:-85}

while read -r FS USED MOUNT; do
  USED=${USED%\%}
  if [ "$USED" -ge "$THRESHOLD" ]; then
    curl -X POST "$SLACK_WEBHOOK" \
      --data "{\"text\":\"$(hostname): $MOUNT at ${USED}% (was ≥ $THRESHOLD)\"}"
  fi
done < <(df -P -x tmpfs -x devtmpfs | awk 'NR>1 {print $1, $5, $6}')

Same thing in Enterno.io

The cron job itself should ping an Enterno heartbeat — if your script silently dies before checking the disk, Enterno still alerts because the ping never arrived.

Set up Heartbeat monitor → ← All recipes

Related recipes