Add disk full incident response toolkit

This commit is contained in:
Mateusz Suski
2026-05-05 21:44:08 +00:00
parent 5dd8c34952
commit 76e24796bb
10 changed files with 742 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=00_env.sh
. "$SCRIPT_DIR/00_env.sh"
SEARCH_PATH="/"
DEPTH=2
TOP_N=25
usage() {
printf 'Usage: %s [--path <path>] [--depth <N>] [--top <N>]\n' "$(basename "$0")"
}
while [[ "$#" -gt 0 ]]; do
case "$1" in
--path) SEARCH_PATH="${2:-}"; shift 2 ;;
--depth) DEPTH="${2:-}"; shift 2 ;;
--top) TOP_N="${2:-}"; shift 2 ;;
-h|--help) usage; exit 0 ;;
*) critical "Unknown argument: $1"; usage; exit 2 ;;
esac
done
if ! [[ "$DEPTH" =~ ^[0-9]+$ ]]; then
critical "--depth must be a non-negative integer"
exit 2
fi
if ! [[ "$TOP_N" =~ ^[0-9]+$ ]] || (( TOP_N < 1 )); then
critical "--top must be a positive integer"
exit 2
fi
validate_path "$SEARCH_PATH" || exit 2
require_cmd du || exit 1
require_cmd sort || exit 1
require_cmd head || exit 1
section "Top Directories Under $SEARCH_PATH"
warning "Read-only scan. Permission errors can be normal without root access."
du -x -h --max-depth="$DEPTH" "$SEARCH_PATH" 2>/dev/null |
sort -hr |
head -n "$TOP_N" |
tee -a "$LOG_FILE"
ok "No directories were modified."