Bash public

Log Directory Usage

Share this script safely, inspect its metadata, and copy the exact command you need.

Dashboard

Ready to run

One-liner

Copy the command, then review before execution.
curl -fsSL https://runny.sh/r/HDSJRZVAKXC2 | bash

Current version: 1.1 · Updated by Godmode · 2026-09-07 02:38:59.432

At a glance

Script metadata

Slug
HDSJRZVAKXC2
Fetches
0
Size
1602 B · 62 lines
Expires
never
Last fetch
Created
2026-09-07 00:36:00.386
Description
Size of /var/log and its heaviest children

Readable before runnable

Preview

#!/usr/bin/env bash
# Log directory usage
# Read-only: du -sh /var/log and the largest subdirectories. Does not truncate logs.
# Exit 0 if under 2 GiB, 1 at >=2 GiB or unreadable, 2 at >=8 GiB.
# Hosted on Runny.sh. Review the script page before you run it.

set -u

status=0
note() { printf '%s\n' "$*"; }
bump() {
  case $1 in
    crit) status=2 ;;
    warn) [ "$status" -lt 1 ] && status=1 ;;
  esac
}

note "=== /var/log disk use ==="
note "Host:     $(hostname 2>/dev/null || printf unknown)"
if [ ! -d /var/log ]; then
  note "/var/log is not a directory on this host"
  note "Result: WARNING"
  exit 1
fi
if ! command -v du >/dev/null 2>&1; then
  note "du:       not found in PATH"
  note "Result: CRITICAL"
  exit 2
fi

bytes=$(du -sb /var/log 2>/dev/null | awk '{print $1}')
human=$(du -sh /var/log 2>/dev/null | awk '{print $1}')
if [ -z "${bytes}" ]; then
  note "Could not read /var/log (permission or empty)"
  bump warn
else
  note "Total:    ${human}  (${bytes} bytes)"
  note ""
  note "Largest subdirectories:"
  du -sh /var/log/* /var/log/.[!.]* 2>/dev/null | sort -hr | head -n 12 | while IFS= read -r row; do
    note "  ${row}"
  done
  note ""
  if [ "$bytes" -ge $((8 * 1024 * 1024 * 1024)) ]; then
    note "          CRITICAL: /var/log is at least 8 GiB"
    bump crit
  elif [ "$bytes" -ge $((2 * 1024 * 1024 * 1024)) ]; then
    note "          WARNING: /var/log is at least 2 GiB"
    bump warn
  else
    note "          OK"
  fi
fi
note ""

case $status in
  0) note "Result: HEALTHY" ;;
  1) note "Result: WARNING" ;;
  *) note "Result: CRITICAL" ;;
esac
exit "$status"

Raw endpointhttps://runny.sh/r/HDSJRZVAKXC2

See something unsafe?

Report this script

Tell us why it should come down. Anyone can also report a URL at /abuse.

Restore revision