Interview Prep/Shell Scripting/Scenarios: health checks, monitoring and alerts

A server reports `No space left on device` but `df -h` shows 40% free. What would you add to the health checks?

BeginnerScenarioScenarios: health checks, monitoring and alerts
Answer

Situation read → The filesystem has run out of inodes, usually from millions of tiny files (sessions, cache, mail queue).

What I'd do →

  1. Confirm: df -i.
  2. Find the directory: find / -xdev -type d -size +1M 2>/dev/null (huge directories) or count files per directory with du --inodes -x -d 2 / | sort -n | tail.
  3. Add an inode check next to the disk check:
    df -Pi -x tmpfs -x devtmpfs | awk -v t=90 'NR > 1 && $5 != "-" {sub(/%/, "", $5); if ($5+0 >= t) print $6, $5"%"}'
    
  4. Fix the source: session cleanup, cache TTLs, tmpfiles rules.

Why → Inode exhaustion fails writes exactly like a full disk but is invisible to df -h.

Interview tip → Mention XFS allocates inodes dynamically while ext4 fixes the count at mkfs time, which is why this hits ext4 more.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: health checks, monitoring and alerts