Bash public

Linux System Health Check

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/D50TC4Y5AC15 | bash

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

At a glance

Script metadata

Slug
D50TC4Y5AC15
Fetches
9
Size
4714 B · 167 lines
Expires
never
Last fetch
2026-09-07 02:17:37.216
Created
2026-09-07 00:35:58.704
Description
Load, memory, disk, and failed systemd units

Readable before runnable

Preview

#!/usr/bin/env bash
# Linux System Health Check
# Read-only report of load, memory, disk, and failed systemd units.
# Exit 0 if healthy, 1 if warnings, 2 if a check is critical.
# Hosted on Runny.sh. Review the script page before you run it.

set -u

status=0
warns=0
crits=0

note() {
  printf '%s\n' "$*"
}

bump() {
  case $1 in
    crit)
      crits=$((crits + 1))
      status=2
      ;;
    warn)
      warns=$((warns + 1))
      if [ "$status" -lt 1 ]; then
        status=1
      fi
      ;;
  esac
}

note "=== Linux system health ==="
note "Host:     $(hostname 2>/dev/null || printf unknown)"
note "Kernel:   $(uname -sr 2>/dev/null || printf unknown)"
if [ -r /proc/uptime ]; then
  up_s=$(awk '{printf "%d", $1}' /proc/uptime)
  note "Uptime:   $((up_s / 86400))d $((up_s % 86400 / 3600))h $((up_s % 3600 / 60))m"
fi
note ""

cpus=$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc 2>/dev/null || printf 1)
if [ -r /proc/loadavg ]; then
  load1=$(awk '{print $1}' /proc/loadavg)
  load5=$(awk '{print $2}' /proc/loadavg)
  load15=$(awk '{print $3}' /proc/loadavg)
  note "Load:     ${load1} ${load5} ${load15}  (${cpus} CPU)"
  awk -v l="$load1" -v n="$cpus" 'BEGIN {
    if (n < 1) n = 1
    if (l >= n * 2) exit 2
    if (l >= n) exit 1
    exit 0
  }'
  case $? in
    2) note "          CRITICAL: 1-minute load is at least 2x CPU count"; bump crit ;;
    1) note "          WARNING: 1-minute load is at or above CPU count"; bump warn ;;
    *) note "          OK" ;;
  esac
else
  note "Load:     /proc/loadavg not readable"
  bump warn
fi
note ""

if [ -r /proc/meminfo ]; then
  mem_total=$(awk '/^MemTotal:/ {print $2}' /proc/meminfo)
  mem_avail=$(awk '/^MemAvailable:/ {print $2}' /proc/meminfo)
  swap_total=$(awk '/^SwapTotal:/ {print $2}' /proc/meminfo)
  swap_free=$(awk '/^SwapFree:/ {print $2}' /proc/meminfo)
  if [ -z "${mem_avail}" ]; then
    mem_free=$(awk '/^MemFree:/ {print $2}' /proc/meminfo)
    mem_cached=$(awk '/^Cached:/ {print $2}' /proc/meminfo)
    mem_avail=$((mem_free + mem_cached))
  fi
  if [ "${mem_total}" -gt 0 ]; then
    mem_used=$((mem_total - mem_avail))
    mem_pct=$((mem_used * 100 / mem_total))
    note "Memory:   ${mem_pct}% used  ($((mem_used / 1024)) / $((mem_total / 1024)) MiB)"
    if [ "$mem_pct" -ge 95 ]; then
      note "          CRITICAL: memory is almost exhausted"
      bump crit
    elif [ "$mem_pct" -ge 85 ]; then
      note "          WARNING: memory pressure is high"
      bump warn
    else
      note "          OK"
    fi
  fi
  if [ "${swap_total:-0}" -gt 0 ]; then
    swap_used=$((swap_total - swap_free))
    swap_pct=$((swap_used * 100 / swap_total))
    note "Swap:     ${swap_pct}% used  ($((swap_used / 1024)) / $((swap_total / 1024)) MiB)"
    if [ "$swap_pct" -ge 80 ]; then
      note "          WARNING: swap is heavily used"
      bump warn
    fi
  else
    note "Swap:     none configured"
  fi
else
  note "Memory:   /proc/meminfo not readable"
  bump warn
fi
note ""

note "Disk:"
disk_seen=0
if command -v df >/dev/null 2>&1; then
  while IFS= read -r line; do
    mount=$(printf '%s\n' "$line" | awk '{print $6}')
    used=$(printf '%s\n' "$line" | awk '{gsub(/%/, "", $5); print $5}')
    avail=$(printf '%s\n' "$line" | awk '{print $4}')
    case "$mount" in
      ''|Mounted|/boot/efi|/snap/*|/run|/run/*|/dev|/dev/*|/sys|/sys/*|/proc|/proc/*) continue ;;
    esac
    case "$used" in
      ''|*[!0-9]*) continue ;;
    esac
    disk_seen=1
    note "  ${mount}: ${used}% used  (${avail} available)"
    if [ "$used" -ge 95 ]; then
      note "           CRITICAL: filesystem is nearly full"
      bump crit
    elif [ "$used" -ge 85 ]; then
      note "           WARNING: filesystem is filling up"
      bump warn
    fi
  done <<EOF
$(df -P -x tmpfs -x devtmpfs -x overlay -x squashfs -x ramfs 2>/dev/null | awk 'NR > 1')
EOF
fi
if [ "$disk_seen" -eq 0 ]; then
  note "  no local filesystems reported"
  bump warn
fi
note ""

if command -v systemctl >/dev/null 2>&1; then
  failed=$(systemctl --failed --no-legend --no-pager --plain 2>/dev/null | awk 'NF {print $1}')
  if [ -z "${failed}" ]; then
    note "systemd:  no failed units"
  else
    count=$(printf '%s\n' "$failed" | grep -c .)
    note "systemd:  ${count} failed unit(s)"
    printf '%s\n' "$failed" | while IFS= read -r unit; do
      [ -n "$unit" ] && note "  - ${unit}"
    done
    if [ "$count" -ge 3 ]; then
      bump crit
    else
      bump warn
    fi
  fi
else
  note "systemd:  not available"
fi
note ""

if [ "$status" -eq 0 ]; then
  note "Result:   HEALTHY"
elif [ "$status" -eq 1 ]; then
  note "Result:   WARNING (${warns} check(s))"
else
  note "Result:   CRITICAL (${crits} critical, ${warns} warning)"
fi

exit "$status"

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

See something unsafe?

Report this script

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

Restore revision