Write a script that alerts when any filesystem is above 80% usage.

BeginnerHands-onBash scripting tasks
Answer
#!/usr/bin/env bash
set -euo pipefail
THRESHOLD="${1:-80}"

df -P -x tmpfs -x devtmpfs | awk -v t="$THRESHOLD" 'NR>1 {
  gsub("%","",$5)
  if ($5+0 > t) printf "ALERT: %s mounted on %s is at %s%%\n", $1, $6, $5
}'

Key trick → df -P forces POSIX one-line-per-filesystem output, so long device names never wrap and break the column numbers.

All Real-World Interview questions Roadmap: Interview readiness

More on Bash scripting tasks